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

R. Michael Weylandt michael.weylandt at gmail.com
Tue Mar 6 03:15:02 CET 2012


What are surfA, surfB? There's nothing to suggest that difcount is
vectorized so if they are vectors of length > 1 that could lead to
your problem.

Michael

On Mon, Mar 5, 2012 at 2:07 PM, Colin Wren <colindwren at gmail.com> wrote:
> 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
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list