Erro !res[[1]] : invalid argument type: shapefile using “sp” e “rgdal”

I'm trying to save a shapefile format with detection rates using the "sp" and "rgdal" packages, but the following error occurs:

Erro !res[[1]] : invalid argument type

The plot was created, but the shapefile was not saved

I did updates of the packages, but the error remain

Reproductive example

library(rgdal)
library(sp)
library(camtrapR)

Long<-c(-53.59390711, -53.58148303)
Lat<-c(-4.633924739, -4.6340598)
df1<-data.frame(Long,Lat)
df1$Station<-NA
df1[df1$Long=="-53.59390711",]$Station<-"w"
df1[df1$Long=="-53.58148303",]$Station<-"z"

Station<-c("w","w","w","w","w","w","w","w","w","w","z","z","z","z","z","z","z","z","z","z")
Species<-c("a","a","a","b","b","b","c","c","c","c","a","b","b","b","b","b","c","c","c","c")
df2<-data.frame(Station, Species)

#no plot

detectionMaps(CTtable=df1,recordTable=df2,Xcol="Long",Ycol="Lat",stationCol="Station",speciesCol="Species",speciesToShow="a",richnessPlot=FALSE,speciesPlots=FALSE,
writeShapefile=TRUE,shapefileDirectory=tempdir(),shapefileName="sp_a", shapefileProjection="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_def")

#The shapefile should be created in this directory: C:\Users\...\AppData\Local\Temp\

#with plot

detectionMaps(CTtable=df1,recordTable=df2,Xcol="Long",Ycol="Lat",stationCol="Station",speciesCol="Species",speciesToShow="a",richnessPlot=T,speciesPlots=T,
writeShapefile=TRUE,shapefileDirectory=tempdir(),shapefileName="sp_a", shapefileProjection="+proj=longlat +ellps=WGS84 +datum=WGS84+no_def") 

Hi @Milton,
I just ran your code and it worked fine on my Windows 10 machine with R-4.0.2

Maybe the arguments to detectionMaps are being truncated on the right-hand side of the
input screen; try indenting them on separate lines like this:

detectionMaps(CTtable=df1,
              recordTable=df2,
              Xcol="Long",
              Ycol="Lat",
              stationCol="Station",
              speciesCol="Species",
              speciesToShow="a",
              richnessPlot=FALSE,
              speciesPlots=FALSE,
              writeShapefile=TRUE,
              shapefileDirectory=tempdir(),
              shapefileName="sp_a", 
              shapefileProjection="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_def")

The output shape files were written to tempdir() which on my machine was

tempdir()
# [1] "C:\\Users\\david\\AppData\\Local\\Temp\\RtmpiESLrZ"

Your subdirectory name will be different but with this pattern: Rtmpxxxxxx

Edit: Thanks for providing such an excellent Reproducible Example!
HTH

Hi @DavoWW,

Thanks a lot for your help.
But, the error remain, I don't know...it seems that the sp package was not working well in my Rstudio, when running library (sp) it is look like the package wasn't loaded...

Best

Also, check that all your packages are updated to the latest versions in case the arguments have changed.

I tried the updates the "sp", but the R showed errors

"package ‘sp’ successfully unpacked and MD5 sums checked
Error in unpackPkgZip(foundpkgs[okp, 2L], foundpkgs[okp, 1L], lib, libs_only, :
ERROR: failed to lock directory ‘C:\Users\Miltinho\Documents\R\win-library\3.6’ for modifying
Try removing ‘C:\Users\Miltinho\Documents\R\win-library\3.6/00LOCK’"

@DavoWW,

I removed the file that was suggested by R.
The error was fixed, but, the shape file wasn't created.

I will broke my head to fix.
Thank you for your attention.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.