21

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) 
Julius Vainora
  • 47,421
  • 9
  • 90
  • 102
HoofarLotusX
  • 562
  • 2
  • 5
  • 11
  • Post some code. i.e. what you tried to do and the error message you got. The `packageVersion(packagename)` and `sessionInfo()` wouldn't hurt either – Simon O'Hanlon Mar 07 '13 at 23:07
  • 1
    it does seem that `rimage` and `ReadImage` are orphaned, but ... `library("sos"); findFn("{read jpeg}")` also finds relevant functions in the `biOps` and `jpeg` packages. Have you tried those? – Ben Bolker Mar 07 '13 at 23:56
  • > 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) – HoofarLotusX Mar 08 '13 at 17:43
  • put this stuff in the question – mdsumner Mar 08 '13 at 23:59
  • Warning in install.packages : package ‘/home/Downloads/jpeg_0.1-8.tar.gz’ is not available (for R version 3.4.0) – Shicheng Guo May 06 '17 at 06:24

2 Answers2

40

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.

mdsumner
  • 29,099
  • 6
  • 83
  • 91
11

also:

## if not already installed
install.packages("jpeg")  

library(jpeg)

?readJPEG()

img <- readJPEG("/Users/name/locationInFileDirectory/image.jpg", native = TRUE)

#this will display your image to test you read it correctly
if(exists("rasterImage")){
      plot(1:2, type='n')
      rasterImage(img,1,1,2,2)
}
za_roxy
  • 111
  • 1
  • 5
  • 1
    This helped because of the full path, I thought this would pay attention to the working directory. – MikeF Mar 28 '18 at 14:27