Re: [R-pkg-devel] Error: [writeRaster] cannot write file
Hi, This works. I think this is also an implementation of what Berry and Duncan suggested earlier. Thanks. Best Regards, Krishna Keshav From: Iris Simmons Date: Monday, October 9, 2023 at 7:37 PM To: Keshav, Krishna Cc: r-package-devel@r-project.org Subject: Re: [R-pkg-devel] Error: [writeRaster] cannot write file [External Email] You wrote # create the plots directory if it does not exist but then created a directory named outdir/plots/typ_Sys.time.tif You need to rewrite the code like: plotsdir <- file.path(outdir, "plots") fp <- file.path(plotsdir, paste(typ, "_", stringr::str_replace_all(Sys.time(), "[^a-zA-Z0-9]", ""), ".tif", sep = "")) # Create the "plots" directory if it doesn't exist if (!dir.exists(plotsdir)) { dir.create(plotsdir, recursive = TRUE) } On Mon, Oct 9, 2023, 15:49 Keshav, Krishna mailto:kkes...@ufl.edu>> wrote: Hi, I am developing an R package where I need to save Raster file with .tif extension to the tempdir(). I am using terra::writeRaster for the same. While it works through R CMD check in mac, it is failing in R hub builder. Snippet �V .saverast <- function(typ, rast, outdir) { if (is.null(outdir) || length(outdir) == 0) { outdir <- tempdir() } # Save the plot as a raster file fp <- file.path(outdir, paste("plots", "/", typ, "_", stringr::str_replace_all(Sys.time(), "[^a-zA-Z0-9]", ""), ".tif", sep = "")) # Create the "plots" directory if it doesn't exist if (!dir.exists(fp)) { dir.create(fp, recursive = TRUE) } terra::writeRaster(rast, overwrite = TRUE, filename = fp, gdal = c("COMPRESS=NONE")) message(paste("raster created", fp, sep = ": "), "\n") } Error �V Error: [writeRaster] cannot write file 12. �|�wgeohabnet:::.saverast(typ, rast, outdir) 13. �u�wterra::writeRaster(rast, overwrite = TRUE, filename = fp, gdal = c("COMPRESS=NONE")) 14. �|�wterra::writeRaster(rast, overwrite = TRUE, filename = fp, gdal = c("COMPRESS=NONE")) 15. �|�wterra (local) .local(x, filename, ...) 16. �|�wterra:::messages(x, "writeRaster") 17. �|�wterra:::error(f, x@pnt$getError()) Best Regards, Krishna Keshav [[alternative HTML version deleted]] __ R-package-devel@r-project.org<mailto:R-package-devel@r-project.org> mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel [[alternative HTML version deleted]] __ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel
Re: [R-pkg-devel] Error: [writeRaster] cannot write file
You wrote # create the plots directory if it does not exist but then created a directory named outdir/plots/typ_Sys.time.tif You need to rewrite the code like: plotsdir <- file.path(outdir, "plots") fp <- file.path(plotsdir, paste(typ, "_", stringr::str_replace_all(Sys.time(), "[^a-zA-Z0-9]", ""), ".tif", sep = "")) # Create the "plots" directory if it doesn't exist if (!dir.exists(plotsdir)) { dir.create(plotsdir, recursive = TRUE) } On Mon, Oct 9, 2023, 15:49 Keshav, Krishna wrote: > Hi, > > I am developing an R package where I need to save Raster file with .tif > extension to the tempdir(). I am using terra::writeRaster for the same. > While it works through R CMD check in mac, it is failing in R hub builder. > Snippet ¡V > .saverast <- function(typ, rast, outdir) { > > if (is.null(outdir) || length(outdir) == 0) { > outdir <- tempdir() > } > > # Save the plot as a raster file > fp <- file.path(outdir, paste("plots", "/", > typ, "_", > stringr::str_replace_all(Sys.time(), > "[^a-zA-Z0-9]", ""), > ".tif", sep = "")) > # Create the "plots" directory if it doesn't exist > if (!dir.exists(fp)) { > dir.create(fp, recursive = TRUE) > } > > terra::writeRaster(rast, overwrite = TRUE, > filename = fp, > gdal = c("COMPRESS=NONE")) > message(paste("raster created", fp, sep = ": "), "\n") > } > > Error ¡V > > Error: [writeRaster] cannot write file >12. ¢|¢wgeohabnet:::.saverast(typ, rast, outdir) >13. ¢u¢wterra::writeRaster(rast, overwrite = TRUE, filename = > fp, gdal = c("COMPRESS=NONE")) >14. ¢|¢wterra::writeRaster(rast, overwrite = TRUE, filename = > fp, gdal = c("COMPRESS=NONE")) >15. ¢|¢wterra (local) .local(x, filename, ...) >16. ¢|¢wterra:::messages(x, "writeRaster") >17. ¢|¢wterra:::error(f, x@pnt$getError()) > > > > Best Regards, > Krishna Keshav > > [[alternative HTML version deleted]] > > __ > R-package-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-package-devel > [[alternative HTML version deleted]] __ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel
Re: [R-pkg-devel] Error: [writeRaster] cannot write file
On 09/10/2023 6:56 p.m., Keshav, Krishna wrote: Outdir is either a directory like getwd(), tempdir() etc or empty/null. If it is empty/null, then I set it to tempdir(). That doesn't answer the question, and the link you provided doesn't answer it either, as far as I can see. In the test and the vignette that generated the errors, something specific was passed as outdir. But what? If it was getwd(), that's bound to fail -- you don't have permission to write there. tempdir() should have worked, but Berry pointed out some other things that might be problems. Duncan Murdoch /if (is.null(outdir) || length(outdir) == 0) { outdir <- tempdir()/ /}/// I am not sure how to debug when running it in Rbuilder. But you can look at results here - https://builder.r-hub.io/status/geohabnet_1.0.0.tar.gz-a2eaa40ccf1d026bbebf5077bfb482d5 <https://builder.r-hub.io/status/geohabnet_1.0.0.tar.gz-a2eaa40ccf1d026bbebf5077bfb482d5> Best Regards, Krishna Keshav *From: *Duncan Murdoch *Date: *Monday, October 9, 2023 at 4:08 PM *To: *Keshav, Krishna , r-package-devel@r-project.org *Subject: *Re: [R-pkg-devel] Error: [writeRaster] cannot write file [External Email] What were you using as "outdir"? On 09/10/2023 2:59 p.m., Keshav, Krishna wrote: Hi, I am developing an R package where I need to save Raster file with .tif extension to the tempdir(). I am using terra::writeRaster for the same. While it works through R CMD check in mac, it is failing in R hub builder. Snippet �V .saverast <- function(typ, rast, outdir) { if (is.null(outdir) || length(outdir) == 0) { outdir <- tempdir() } # Save the plot as a raster file fp <- file.path(outdir, paste("plots", "/", typ, "_", stringr::str_replace_all(Sys.time(), "[^a-zA-Z0-9]", ""), ".tif", sep = "")) # Create the "plots" directory if it doesn't exist if (!dir.exists(fp)) { dir.create(fp, recursive = TRUE) } terra::writeRaster(rast, overwrite = TRUE, filename = fp, gdal = c("COMPRESS=NONE")) message(paste("raster created", fp, sep = ": "), "\n") } Error �V Error: [writeRaster] cannot write file 12. �|�wgeohabnet:::.saverast(typ, rast, outdir) 13. �u�wterra::writeRaster(rast, overwrite = TRUE, filename = fp, gdal = c("COMPRESS=NONE")) 14. �|�wterra::writeRaster(rast, overwrite = TRUE, filename = fp, gdal = c("COMPRESS=NONE")) 15. �|�wterra (local) .local(x, filename, ...) 16. �|�wterra:::messages(x, "writeRaster") 17. �|�wterra:::error(f, x@pnt$getError()) Best Regards, Krishna Keshav [[alternative HTML version deleted]] __ R-package-devel@r-project.org mailing list https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-package-devel&data=05%7C01%7Ckkeshav%40ufl.edu%7Cddd83781762040d664dc08dbc9038ec7%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C638324789348072931%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=mBzV%2BSJoOTTnSpRzu0EvLT8sZ2NJ1OlhSGXqNCvGWB4%3D&reserved=0 <https://stat.ethz.ch/mailman/listinfo/r-package-devel> __ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel
Re: [R-pkg-devel] Error: [writeRaster] cannot write file
Outdir is either a directory like getwd(), tempdir() etc or empty/null. If it is empty/null, then I set it to tempdir(). if (is.null(outdir) || length(outdir) == 0) { outdir <- tempdir() } I am not sure how to debug when running it in Rbuilder. But you can look at results here - https://builder.r-hub.io/status/geohabnet_1.0.0.tar.gz-a2eaa40ccf1d026bbebf5077bfb482d5 Best Regards, Krishna Keshav From: Duncan Murdoch Date: Monday, October 9, 2023 at 4:08 PM To: Keshav, Krishna , r-package-devel@r-project.org Subject: Re: [R-pkg-devel] Error: [writeRaster] cannot write file [External Email] What were you using as "outdir"? On 09/10/2023 2:59 p.m., Keshav, Krishna wrote: > Hi, > > I am developing an R package where I need to save Raster file with .tif > extension to the tempdir(). I am using terra::writeRaster for the same. While > it works through R CMD check in mac, it is failing in R hub builder. > Snippet �V > .saverast <- function(typ, rast, outdir) { > >if (is.null(outdir) || length(outdir) == 0) { > outdir <- tempdir() >} > ># Save the plot as a raster file >fp <- file.path(outdir, paste("plots", "/", > typ, "_", > stringr::str_replace_all(Sys.time(), > "[^a-zA-Z0-9]", ""), > ".tif", sep = "")) > # Create the "plots" directory if it doesn't exist >if (!dir.exists(fp)) { > dir.create(fp, recursive = TRUE) >} > >terra::writeRaster(rast, overwrite = TRUE, > filename = fp, > gdal = c("COMPRESS=NONE")) >message(paste("raster created", fp, sep = ": "), "\n") > } > > Error �V > >Error: [writeRaster] cannot write file > 12. �|�wgeohabnet:::.saverast(typ, rast, outdir) > 13. �u�wterra::writeRaster(rast, overwrite = TRUE, filename = > fp, gdal = c("COMPRESS=NONE")) > 14. �|�wterra::writeRaster(rast, overwrite = TRUE, filename = > fp, gdal = c("COMPRESS=NONE")) > 15. �|�wterra (local) .local(x, filename, ...) > 16. �|�wterra:::messages(x, "writeRaster") > 17. �|�wterra:::error(f, x@pnt$getError()) > > > > Best Regards, > Krishna Keshav > > [[alternative HTML version deleted]] > > > __ > R-package-devel@r-project.org mailing list > https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-package-devel&data=05%7C01%7Ckkeshav%40ufl.edu%7Cddd83781762040d664dc08dbc9038ec7%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C638324789348072931%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=mBzV%2BSJoOTTnSpRzu0EvLT8sZ2NJ1OlhSGXqNCvGWB4%3D&reserved=0<https://stat.ethz.ch/mailman/listinfo/r-package-devel> [[alternative HTML version deleted]] __ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel
Re: [R-pkg-devel] Error: [writeRaster] cannot write file
Are you intentionally running dir.exists on _file_names? dir.exists("existing_folder/imaginary.file") shows FALSE, somwhat counterintuitively. You might want to wrap the filenames in dirname... Regards, Berry From: R-package-devel on behalf of Keshav, Krishna Sent: Monday, October 9, 2023 20:59 To: r-package-devel@r-project.org Subject: [R-pkg-devel] Error: [writeRaster] cannot write file Hi, I am developing an R package where I need to save Raster file with .tif extension to the tempdir(). I am using terra::writeRaster for the same. While it works through R CMD check in mac, it is failing in R hub builder. Snippet �V .saverast <- function(typ, rast, outdir) { if (is.null(outdir) || length(outdir) == 0) { outdir <- tempdir() } # Save the plot as a raster file fp <- file.path(outdir, paste("plots", "/", typ, "_", stringr::str_replace_all(Sys.time(), "[^a-zA-Z0-9]", ""), ".tif", sep = "")) # Create the "plots" directory if it doesn't exist if (!dir.exists(fp)) { dir.create(fp, recursive = TRUE) } terra::writeRaster(rast, overwrite = TRUE, filename = fp, gdal = c("COMPRESS=NONE")) message(paste("raster created", fp, sep = ": "), "\n") } Error �V Error: [writeRaster] cannot write file 12. �|�wgeohabnet:::.saverast(typ, rast, outdir) 13. �u�wterra::writeRaster(rast, overwrite = TRUE, filename = fp, gdal = c("COMPRESS=NONE")) 14. �|�wterra::writeRaster(rast, overwrite = TRUE, filename = fp, gdal = c("COMPRESS=NONE")) 15. �|�wterra (local) .local(x, filename, ...) 16. �|�wterra:::messages(x, "writeRaster") 17. �|�wterra:::error(f, x@pnt$getError()) Best Regards, Krishna Keshav [[alternative HTML version deleted]] [[alternative HTML version deleted]] __ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel
Re: [R-pkg-devel] Error: [writeRaster] cannot write file
What were you using as "outdir"? On 09/10/2023 2:59 p.m., Keshav, Krishna wrote: Hi, I am developing an R package where I need to save Raster file with .tif extension to the tempdir(). I am using terra::writeRaster for the same. While it works through R CMD check in mac, it is failing in R hub builder. Snippet �V .saverast <- function(typ, rast, outdir) { if (is.null(outdir) || length(outdir) == 0) { outdir <- tempdir() } # Save the plot as a raster file fp <- file.path(outdir, paste("plots", "/", typ, "_", stringr::str_replace_all(Sys.time(), "[^a-zA-Z0-9]", ""), ".tif", sep = "")) # Create the "plots" directory if it doesn't exist if (!dir.exists(fp)) { dir.create(fp, recursive = TRUE) } terra::writeRaster(rast, overwrite = TRUE, filename = fp, gdal = c("COMPRESS=NONE")) message(paste("raster created", fp, sep = ": "), "\n") } Error �V Error: [writeRaster] cannot write file 12. �|�wgeohabnet:::.saverast(typ, rast, outdir) 13. �u�wterra::writeRaster(rast, overwrite = TRUE, filename = fp, gdal = c("COMPRESS=NONE")) 14. �|�wterra::writeRaster(rast, overwrite = TRUE, filename = fp, gdal = c("COMPRESS=NONE")) 15. �|�wterra (local) .local(x, filename, ...) 16. �|�wterra:::messages(x, "writeRaster") 17. �|�wterra:::error(f, x@pnt$getError()) Best Regards, Krishna Keshav [[alternative HTML version deleted]] __ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel __ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel
[R-pkg-devel] Error: [writeRaster] cannot write file
Hi, I am developing an R package where I need to save Raster file with .tif extension to the tempdir(). I am using terra::writeRaster for the same. While it works through R CMD check in mac, it is failing in R hub builder. Snippet �V .saverast <- function(typ, rast, outdir) { if (is.null(outdir) || length(outdir) == 0) { outdir <- tempdir() } # Save the plot as a raster file fp <- file.path(outdir, paste("plots", "/", typ, "_", stringr::str_replace_all(Sys.time(), "[^a-zA-Z0-9]", ""), ".tif", sep = "")) # Create the "plots" directory if it doesn't exist if (!dir.exists(fp)) { dir.create(fp, recursive = TRUE) } terra::writeRaster(rast, overwrite = TRUE, filename = fp, gdal = c("COMPRESS=NONE")) message(paste("raster created", fp, sep = ": "), "\n") } Error �V Error: [writeRaster] cannot write file 12. �|�wgeohabnet:::.saverast(typ, rast, outdir) 13. �u�wterra::writeRaster(rast, overwrite = TRUE, filename = fp, gdal = c("COMPRESS=NONE")) 14. �|�wterra::writeRaster(rast, overwrite = TRUE, filename = fp, gdal = c("COMPRESS=NONE")) 15. �|�wterra (local) .local(x, filename, ...) 16. �|�wterra:::messages(x, "writeRaster") 17. �|�wterra:::error(f, x@pnt$getError()) Best Regards, Krishna Keshav [[alternative HTML version deleted]] __ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel