'In R, after installed a package,' pixmap', Error in file(file, open = "rb") : cannot open the connection

I'm learning R programming, using the book, "The Art of R Programming". In chapter 3.2.3 Extended Example: Image Manipulation. The author Matloff tries to use a Mount Rushmore gray-scale image to illustrate that the image is stored in matrix. He used a library called pixmap. And I downloaded the package, installed it.

> library(pixmap)
> mtrush1 <- read.pnm("mtrush1.pgm")
> mtrush1
Pixmap image
  Type          : pixmapGrey
  Size          : 194x259
  Resolution    : 1x1
  Bounding box  : 0 0 259 194
> plot(mtrush1) 

This is what the book has written, and I tried to run this, but got the error message,

> library(pixmap)
> mtrush1 <- read.pnm("mtrush1.pgm")
Error in file(file, open = "rb") : cannot open the connection
In addition: Warning message:
In file(file, open = "rb") :
  cannot open file 'mtrush1.pgm': No such file or directory
starting httpd help server ... done

What does this mean? cannot open the connection? And also the mtrush1.pgm does not exist? How should I fix it here? Any help? Much appreciated.



Solution 1:[1]

Summary:

Add the argument cellres=1 to your function call and you should be fine.


Answer:

The second error you saw--Warning message: In rep(cellres, length = 2) : 'x' is NULL so the result will be NULL--is because you haven't set the cellres argument and, as a result, "cellres" assumes its default value (i.e. 'NULL'--hence the warning). For what you're working on, setting the cellres argument to 1 will do the trick (though you can pass in a two-element vector with unequal values and see just how it affects your figure by plotting the resulting object).

Note: Though it's a little late to be answering, I figure that since I had the same problem earlier today (and since Google was no help) a response was probably warranted.

Solution 2:[2]

This means that the file mtrush1.pgm is not in current directory. You should either setwd to the directory that contains this file, or specify the complete path in read.pnm.

For the file mtrush1.pgm, you can download it from http://heather.cs.ucdavis.edu/~matloff/

Solution 3:[3]

The file mtrush1.pgm and the R scripts from the book "The Art Of R Programming" can be found at this GitHub site.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community
Solution 2 alittleboy
Solution 3