On 18/04/2020 5:55 p.m., Jeff Newmiller wrote:
See below:
On Sat, 18 Apr 2020, David Andres Zamora Avila wrote:
Thanks for your answers.
This a part of my script where it creates files and saves it in
path. I am not pretty secure how use file.path() or tempdir(). Can
me more details about it, please?
if (!exists("path_pet")){
path_pet <- getwd()
} else if (!exists("path_p")){
path_p <- getwd()
} else if (!exists("path_p") | !exists("path_pet")){
path_pet <- getwd()
path_p <- getwd()
}
The above code should not exist. You are making a package, so you are
putting it into a function and either looking for the existence of
variables (side effects! requiring user to use special variable
this is not good!), or the "path_pet" and "path_p" variables were
in your function and you should already know that they exist.
If we assume that "path_pet" and "path_p" are parameters to this
function you are writing, like so:
myfunc <- function( x, y, ..., path_pet = getwd(), path_p = getwd() )
...
}
then the user can let the default be the current working directory,
specify which directories the function should work in. Specifically,
you are writing your examples or test code and pretending to be a
you can create a temporary directory and use it like so:
I think your advice would probably pass the checks, but it's bad
advice,
because it leaves the user vulnerable to having files wiped out by
myfunc().
Functions shouldn't write to the current directory unless the user
explicitly asks for it.
A better header would be
myfunc <- function( x, y, ..., path_pet = temp.dir(), path_p =
temp.dir() ) {
Then the user has to explicitly code "path_pet = getwd()" to wipe out
their own files.
Duncan Murdoch
workingdir <- tempdir(TRUE)
result <- myfunc( A, B, path_pet = workingdir, path_p = workingdir )
which means you can then clean up after yourself with
unlink( workingdir, recursive = TRUE )
I don't think this question is really about R packages anymore... if
still cannot read the help files to figure out your questions about
do manage temporary files then you should probably make a small
reproducible example(!!) and post a question on R-help.
(end of comments)
if (file_type == "raster"){
# ---- identify raster format and loading----
if (format == "GTiff"){
if( length(list.files(path_pet, pattern = ".tif")) == 0 |
list.files(path_p, pattern = ".tif")) == 0){
stop("Not avaliable data of precipitation or
}
pet_files <- list.files(path_pet)
pet <- raster::stack(paste(path_pet, pet_files, sep = ""))
p_files <- list.files(path_p)
Kind regards,
David Zamora
El jue., 16 abr. 2020 a las 17:12, Uwe Ligges (<
ligges at statistik.tu-dortmund.de>) escribi?:
On 16.04.2020 20:09, Duncan Murdoch wrote:
On 16/04/2020 1:11 p.m., David Andres Zamora Avila wrote:
Hi,
I submitted my package in CRAN and always appearance the next
Flavor: r-devel-linux-x86_64-debian-gcc
Check: for detritus in the temp directory, Result: NOTE
Found the following files/directories:
'RtmpcDoRWjr.nc'
I have tried to solve it in several ways (like if(interactive()),
I not
sure how can I solve it.
How was the file created? What the check wants is that you delete
when you are finished with it. You can use the unlink() function
Or better create it in tempdir(): I guess you used paste(tempdir(),
instead of file.path() and got afilename one level above tempdir()?
Best,
Uwe Ligges