2

I'm trying to read a pgm file in R. I set my wd to where the image is and then simply try to read it:

   setwd("~/3 Diplomado/5 Multivariado/lfwcrop_grey/faces")

   library(pixmap)

    x <- read.pnm(system.file("Aaron_Guiel_0001.pgm", package="pixmap")[1])

But I get the following error:

Error in if (ch == "#") { : argument is of length zero In addition: Warning message: In file(file, open = "rb") : file("") only supports open = "w+" and open = "w+b": using the former

Not sure what it is. I think it simply doesnt find the image. What am I doing wrong? any hints? Thank you in advanced!

J.

Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453
JEquihua
  • 1,217
  • 3
  • 20
  • 40
  • Why not using x=read.pnm(file = "Aaron_Guiel_0001.pgm")? Can you provide a sample file? – Ali Oct 10 '12 at 18:57
  • Not sure, I checked the package example and that was the sintax they used (the one I copied). Yours works fine for me. Thank you. Do you know what is the convenience of doing it as I tried to, even though it failed for me? – JEquihua Oct 10 '12 at 20:03
  • I have added the answer to your question. – Ali Oct 10 '12 at 21:14

1 Answers1

1

Simply try this one:

x=read.pnm(file = "Aaron_Guiel_0001.pgm")

The system.file() is used to find the full path of the files included in packages. It is used in the package example, but you don't need to use it while reading your own file.

Ali
  • 9,440
  • 12
  • 62
  • 92