[R-pkg-devel] How to write example results to a tempdir()?

Jose A Guijarro jguijarrop at aemet.es
Wed Apr 25 19:45:37 CEST 2018


Many thanks for your advise, Sarah!

I will try to implement it. (Now I will have to change all my reading and
writing sentences of all my functions, because they read/write from/to
the users working directory...)

Best regards,

     Jose

El 25/04/18 a las 19:32, Sarah Goslee escribió:
> Don't change the working directory! That has all kinds of unpleasant
> side effects for the unsuspecting user, possibly even more so than
> writing to a file.
>
> Instead, write the file to the temp directory, and read it from there, with e.g.
>
> wd <- tempdir()
> write(dat, file.path(wd, 'Ttest_1981-2000.dat'))
>
> Using file.path() means that the appropriate path delimiter for that
> OS will be used.
>
> Sarah
>
>
> On Wed, Apr 25, 2018 at 12:30 PM, Jose A Guijarro <jguijarrop at aemet.es> wrote:
>> Dear all,
>>
>> I am struggling to update my package climatol from version 3.0 to 3.1.
>> The old version had all examples under a "dontrun" section because they
>> needed files created by other examples that the user had to run first.
>>
>> As this is not acceptable anymore, I made the examples runnable and
>> prepared small ad-hoc datasets, but then writing files to the user space
>> is against the CRAN policy rules, and I was suggested to run them on a
>> temporal directory. Therefore I changed all my examples to read/write
>> files to a tempdir(), as in:
>>
>> \examples{
>> #Set a temporal working directory and write input files:
>> wd <- tempdir()
>> setwd(wd)
>> data(Ttest) #(This loads matrix 'dat' and data.frame 'est.c')
>> write(dat,'Ttest_1981-2000.dat')
>> write.table(est.c,'Ttest_1981-2000.est',row.names=FALSE,col.names=FALSE)
>> rm(dat,est.c) #remove loaded data from memory space
>> #Now run the example:
>> dd2m('Ttest',1981,2000)
>> #Input and output files can be found in directory:
>> print(wd)
>> }
>>
>> But now CRAN checks return this warning ten times (one for every example
>> in the package):
>>
>> Warning: working directory was changed to ‘/tmp/RtmpWSRK2F’, resetting
>>
>> Any hint on how to solve the problem will be highly appreciated...
>>
>> Jose
>>
>

-- 
Firma
Dr. José A. Guijarro
Logotipo de Aemet
Delegación Territorial en Illes Balears
Jefe de la Unidad de Estudios Meteorológicos del Mediterráneo
Tel. (+34) 971145409       (Tno. interno: 50790)
www.aemet.es <http://www.aemet.es>
<https://www.facebook.com/AgenciaEstatalMeteorologia/> 
<https://twitter.com/AEMET_Baleares/> 
<https://www.youtube.com/channel/UCd-ceYPisAtCmmoZa26I-5g> 
<https://aemetblog.es/>



More information about the R-package-devel mailing list