0

When sending my package to CRAN, I received the warning "but you must not write to the user filespace in examples, please use the session dir via tempdir ()."

However, it includes a conditional to save and in my example I put it as FALSE.

In the function:

if(save==T){
    
    fileout <- tempfile(fileext = ".docx")
    fileout <- paste(getwd(),"/Inventario Florestal - ",nm,".docx",sep="")
    print(doc, target = fileout)
  }

In my example, I tried to save to tempdir, but it seems that the files are still being saved in the "packagename.Rcheck" folder

\dontshow{.old_wd <- setwd(tempdir())}
IF_ace <- ace(est2,a=0.1,aj=c(12.6,10.2),save=FALSE)
\dontshow{setwd(.old_wd)}

As I understand it, it seems that this did not happen for Windows, only for: Flavor: r-devel-linux-x86_64-debian-gcc

Would anyone have a solution?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Igor Cobelo
  • 419
  • 3
  • 12

1 Answers1

1

Yes, use a temporary file. I once submitted a patch to tempfile to let you choose the ending:

 fileout <- tempfile(pattern="InventarioFlorestal", fileext=".docx")

which eg right now on my machine yields

 R> fileout <- tempfile(pattern="InventarioFlorestal", fileext=".docx")    
 R> fileout                  
 [1] "/tmp/RtmpYMJRFT/InventarioFlorestal33903b5d616240.docx"         
 R>  

a filename with the correct extension that you can a) write to and b) does not stay behind in the user filespace which CRAN (correctly!) complains about.

Edit: And your original code was already moving into that direction:

fileout <- tempfile(fileext = ".docx")
fileout <- paste(getwd(),"/Inventario Florestal - ",nm,".docx",sep="")

but the second line overwrites the assignment from the first (!!) so that you always end up creating a file relative to the current working directory -- where CRAN does not want you to write.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725