Skip to content
Back to formatted view

Raw Message

Message-ID: <GV2PR02MB877038BD348BA8712953B3EAD5CEA@GV2PR02MB8770.eurprd02.prod.outlook.com>
Date: 2023-10-09T20:13:15Z
From: Berry Boessenkool
Subject: [R-pkg-devel] Error: [writeRaster] cannot write file
In-Reply-To: <SJ0PR22MB2448CB5ADC64FF3B1C14B977B6CEA@SJ0PR22MB2448.namprd22.prod.outlook.com>

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 <r-package-devel-bounces at r-project.org> on behalf of Keshav, Krishna <kkeshav at ufl.edu>
Sent: Monday, October 9, 2023 20:59
To: r-package-devel at r-project.org <r-package-devel at 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 at pnt$getError())



Best Regards,
Krishna Keshav

        [[alternative HTML version deleted]]


	[[alternative HTML version deleted]]