how to read.jpeg in R 2.15

HoofarLotusX picture HoofarLotusX · Mar 7, 2013 · Viewed 49.9k times · Source

It seems very trivial but I can't read in jpeg, or any type of image into R 2.15. In R 2.10 I could do it using rimage library or ReadImage library - with read.jpeg for example - but there seems to be no way to do it in R 2.15 and later versions. Any thoughts on this?

library('ReadImages') 
Error in library("ReadImages") : there is no package called ‘ReadImages’ > 
install.packages('ReadImages') Installing package(s) into ‘C:/Program Files/R/R-2.15.1/library’ (as ‘lib’ is unspecified) 

Warning in install.packages : package ‘ReadImages’ is not available (for R version 2.15.1) 

Answer

mdsumner picture mdsumner · Mar 9, 2013

As pointed out in comments, try the jpeg package.

install.packages("jpeg")  ## if necessary

library(jpeg)
## get help
library(help = jpeg)
## get more help
?readJPEG

Example, from the help:

# read a sample file (R logo)
img <- readJPEG(system.file("img", "Rlogo.jpg", package="jpeg"))

Another option is rgdal, which can read from a massive bestiary of formats. Plotting and manipulation are handled differently.

install.packages("rgdal") ## if necessary
library(rgdal)
img <- readGDAL(file.path(R.home(), "doc", "html", "logo.jpg"))

There is also the readbitmap package on CRAN, it's always worth a basic search of the packages list for what you are looking for.