简体   繁体   中英

How to bypass permission denied error?

The following example writes a point shapefile to disc. However, I get an error when the script tries to write a shapefile to C:/. I am able to write to a external hard drive though (G:/). The following is the error I receive in R:

Error in file(out.name, "wb") : cannot open the connection In addition: Warning message: In file(out.name, "wb") : cannot open file 'c:/test.shp': Permission denied

How can I bypass or resolve this error?

# available from: cran.r-project.org/web/packages/shapefiles/shapefiles.pdf
# Samples of using the convert.to.shapefile function to write out simple shapefiles
# from basic R data.frames

require(shapefiles)
require(maptools)

dd <- data.frame(Id=c(1,2),X=c(3,5),Y=c(9,6))
ddTable <- data.frame(Id=c(1,2),Name=c("Item1","Item2"))
ddShapefile <- convert.to.shapefile(dd, ddTable, "Id", 1)
write.shapefile(ddShapefile, "C:/test", arcgis=T)
shape <- readShapePoints("C:/test")
plot(shape)

Simple answer, do not write to the root-level directory of the system volume.

There are a few good reasons to create files/directories at the root of C: , but this isn't one of them. Use C:/Temp/test instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM