-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?

Community
  • 1
  • 1
S Das
  • 3,291
  • 6
  • 26
  • 41

1 Answers1

5

Here's some starter code you can build on:

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)
hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
  • 1
    Paul Murrell added a plot method for raster images in r-devel, so in the future you'll be able to do `plot(img)` – hadley Jan 31 '15 at 13:15