-1

While using rvest package I am trying to print/show the lego_movie poster in R. I fail to do so. Here's my attempts:

library(rvest)
poster <- lego_movie %>%
  html_nodes("#img_primary img") %>%
  html_attr("src")

## 1st attempt
library(jpeg)
jpeg(poster)
dev.off()

## 2nd attempt
readJPEG(poster)
dev.off()

I think EBImage has display function. This package can't be installed in R-3.1.2. It shows the warning message: package ‘EBImage’ is not available (for R version 3.1.2).

The bottom line of my question is: how to see the jpeg file in R as a display without using EBImage package?

Few related questions:

Plot a JPG image using base graphics in R

How to save a plot as image on the disk?

4

1 回答 1

5

以下是您可以构建的一些入门代码:

library(rvest)
library(httr)
library(jpeg)

lego_movie <- html("http://www.imdb.com/title/tt1490017/")

poster <- lego_movie %>%
  html_nodes("#img_primary img") %>%
  html_attr("src")

GET(poster, write_disk("lego.jpg"))
img <- readJPEG("lego.jpg")
plot(1:2, type='n')
rasterImage(img, 1, 1.25, 1.1, 1)
于 2015-01-30T02:45:59.290 回答