[R] Error in file(fname, "r") : invalid 'description' argument when running maptools' readAsciiGrid on a dataframe

Colin Wren colindwren at gmail.com
Mon Mar 5 20:07:07 CET 2012


Hi,
I'm trying to calculate a sum of differences between two ascii grids.
I have the file names of the two grid files in a data.frame along with
other data. I'm then trying to add a new column to the data.frame with
the result of that calculation.

eg.

library(maptools)
difcount <- function(surfA, surfB) {
  A <- readAsciiGrid(surfA, colname="a")
  B <- readAsciiGrid(surfB, colname="b")
  sum(A$a - B$b)
}
attach(mydataframe)
difcount(surfA[1],surfB[1]) #this test part works fine and gives me
the correct result

#But when I try to do a batch job by running the function against each
row of the table it fails
mydataframe["TotalDif"] <- difcount(surfA,surfB)

Error in file(fname, "r") : invalid 'description' argument

This error seems to be coming from the readAsciiGrid function, but its
being given the same entry so I don't understand why it fails. Any
ideas?

Thanks,
Colin



More information about the R-help mailing list