Re: [R-pkg-devel] nparACT package: "working directory was changed to...resetting"

2017-12-19 Thread Duncan Murdoch

On 19/12/2017 10:27 AM, Blume Christine wrote:

Hi Duncan,

Thanks a lot! Good to see that you had a similar idea, I did just 
that...in my example it looks like this, however, that does not help, 
i.e. that is the code that is associated with the warning…


data(sleepstudy)

wd <- getwd()

name <- "sleepstudy_example"

newdir <- paste(wd,name, sep="/")

if (dir.exists(newdir)){

setwd(newdir)

write.table(sleepstudy, file = "sleepstudy.txt", row.names=FALSE, 
col.names = FALSE)


r <- nparACT_flex_loop(newdir, SR = 4/60, minutes = 435)

} else {

dir.create(newdir)


This is probably a bad idea.  You're creating a subdirectory in the 
user's current working directory; you might not have file system 
permission to do that, and you probably don't have authorization from 
the user to do that.  I don't remember if CRAN checks for this, but I 
wouldn't be surprised if they do, or will in the future.


Since you need to write a file, you want to be sure that it's going to a 
place that is harmless and will succeed.  That's what tempdir() is for. 
At the end of your session it will be cleaned up, so you won't leave 
behind junk for the user.


So I would set newdir using

newdir <- file.path(tempdir(), name)

The other change I would make is to unconditionally use 
dir.create(newdir, showWarnings = FALSE).  You can be almost 100% sure 
that any error creating newdir will be just that it already exists, and 
since it's just somewhere in tempdir(), you don't really care about 
that.  This will simplify your example quite a bit.


Putting these two and my earlier suggestion together, your example becomes

data(sleepstudy)

name <- "sleepstudy_example"

newdir <- file.path(tempdir(),name)

dir.create(newdir, showWarnings = FALSE)

olddir <- setwd(newdir)

write.table(sleepstudy, file = "sleepstudy.txt", row.names=FALSE, 
col.names = FALSE)


r <- nparACT_flex_loop(newdir, SR = 4/60, minutes = 435)

setwd(olddir)

Duncan Murdoch





setwd(newdir)

write.table(sleepstudy, file = "sleepstudy.txt", row.names=FALSE, 
col.names = FALSE)


r <- nparACT_flex_loop(newdir, SR = 4/60, minutes = 435)

}

setwd(wd)

}

Best,

Christine

-Ursprüngliche Nachricht-
Von: Duncan Murdoch [mailto:murdoch.dun...@gmail.com]
Gesendet: Dienstag, 19. Dezember 2017 16:19
An: Blume Christine; r-package-devel@r-project.org
Betreff: Re: [R-pkg-devel] nparACT package: "working directory was 
changed to...resetting"


On 19/12/2017 9:42 AM, Blume Christine wrote:

 > Dear Community,

 >

 >

 >

 > For Fedora my package now gives a warning message when running the 
example:


 >

 >

 >

 > "Warning: working directory was changed to 
'/data/gannet/ripley/R/packages/tests-clang/nparACT.Rcheck/sleepstudy_example', 
resetting"


 >

 >

 >

 > I do not really know how to approach/solve this, what has recently 
been changed in R devel so this error message started appearing?


Previously you were allowed to change directory in an example.  Now 
you're not.  This makes sense:  the user might not want to change the 
working directory.


To fix this, just save the old directory, and restore it at the end of 
your example.  For example,


    olddir <- setwd(tempdir())

    # Run the rest of the example code here

    setwd(olddir)

Duncan Murdoch

 >

 >

 >

 > The full message can be seen here:

 > https://CRAN.R-project.org/web/checks/check_results_nparACT.html

 >

 >

 >

 > Any help is appreciated and rewarded with gratitude.

 >

 >

 >

 > Best,

 >

 >

 >

 > Christine

 >

 >

 >

 >     [[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


 >



__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel

Re: [R-pkg-devel] nparACT package: "working directory was changed to...resetting"

2017-12-19 Thread Blume Christine
Actually, the report I received refers to the old 0.7 version…for whatever 
reason? The version I had submitted  was 0.8 in which I had corrected this. 
Well, let’s see…



Another issue seems to be that the text file the example is supposed to read in 
is not read (properly) using Debian:



Warning in is.na(data$activity) :

 is.na() applied to non-(list or vector) of type 'NULL'

Error in 1:a : argument of length 0



I am reading in a text file with a numeric column (data$activity) and date or 
datetime (which is then converted using as.POSIXct. Subsequently, I check if 
there are NAs…



Any ideas what might be happening here?



Best,

Christine





-Ursprüngliche Nachricht-
Von: Iñaki Úcar [mailto:i.uca...@gmail.com]
Gesendet: Dienstag, 19. Dezember 2017 16:48
An: Blume Christine
Cc: r-package-devel@r-project.org
Betreff: Re: [R-pkg-devel] nparACT package: "working directory was changed 
to...resetting"



2017-12-19 16:27 GMT+01:00 Blume Christine 
<christine.bl...@sbg.ac.at<mailto:christine.bl...@sbg.ac.at>>:

> Hi Duncan,

>

> Thanks a lot! Good to see that you had a similar idea, I did just that...in 
> my example it looks like this, however, that does not help, i.e. that is the 
> code that is associated with the warning…

>

> data(sleepstudy)

>

> wd <- getwd()

>

> name <- "sleepstudy_example"

>

> newdir <- paste(wd,name, sep="/")

>

> if (dir.exists(newdir)){

>

> setwd(newdir)

>

> write.table(sleepstudy, file = "sleepstudy.txt", row.names=FALSE, col.names = 
> FALSE)

>

> r <- nparACT_flex_loop(newdir, SR = 4/60, minutes = 435)

>

> } else {

>

> dir.create(newdir)

>

> setwd(newdir)

>

> write.table(sleepstudy, file = "sleepstudy.txt", row.names=FALSE, col.names = 
> FALSE)

>

> r <- nparACT_flex_loop(newdir, SR = 4/60, minutes = 435)

>

> }

>

> setwd(wd)

>

> }



I see:



$ wget https://cran.r-project.org/src/contrib/nparACT_0.7.tar.gz

$ tar xf nparACT_0.7.tar.gz

$ grep -r setwd nparACT

nparACT/man/nparACT_flex_loop.Rd:setwd(newdir)

nparACT/man/nparACT_base_loop.Rd:setwd(newdir)



so two examples don't restore the wd as Duncan was pointing out.



Iñaki



>

>

>

> Best,

>

> Christine

>

>

[[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] nparACT package: "working directory was changed to...resetting"

2017-12-19 Thread Iñaki Úcar
2017-12-19 16:27 GMT+01:00 Blume Christine :
> Hi Duncan,
>
> Thanks a lot! Good to see that you had a similar idea, I did just that...in 
> my example it looks like this, however, that does not help, i.e. that is the 
> code that is associated with the warning…
>
> data(sleepstudy)
>
> wd <- getwd()
>
> name <- "sleepstudy_example"
>
> newdir <- paste(wd,name, sep="/")
>
> if (dir.exists(newdir)){
>
> setwd(newdir)
>
> write.table(sleepstudy, file = "sleepstudy.txt", row.names=FALSE, col.names = 
> FALSE)
>
> r <- nparACT_flex_loop(newdir, SR = 4/60, minutes = 435)
>
> } else {
>
> dir.create(newdir)
>
> setwd(newdir)
>
> write.table(sleepstudy, file = "sleepstudy.txt", row.names=FALSE, col.names = 
> FALSE)
>
> r <- nparACT_flex_loop(newdir, SR = 4/60, minutes = 435)
>
> }
>
> setwd(wd)
>
> }

I see:

$ wget https://cran.r-project.org/src/contrib/nparACT_0.7.tar.gz
$ tar xf nparACT_0.7.tar.gz
$ grep -r setwd nparACT
nparACT/man/nparACT_flex_loop.Rd:setwd(newdir)
nparACT/man/nparACT_base_loop.Rd:setwd(newdir)

so two examples don't restore the wd as Duncan was pointing out.

Iñaki

>
>
>
> Best,
>
> Christine
>
>

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel

Re: [R-pkg-devel] nparACT package: "working directory was changed to...resetting"

2017-12-19 Thread Blume Christine
Hi Duncan,



Thanks a lot! Good to see that you had a similar idea, I did just that...in my 
example it looks like this, however, that does not help, i.e. that is the code 
that is associated with the warning…



data(sleepstudy)

wd <- getwd()

name <- "sleepstudy_example"

newdir <- paste(wd,name, sep="/")

if (dir.exists(newdir)){

setwd(newdir)

write.table(sleepstudy, file = "sleepstudy.txt", row.names=FALSE, col.names = 
FALSE)

r <- nparACT_flex_loop(newdir, SR = 4/60, minutes = 435)

} else {

dir.create(newdir)

setwd(newdir)

write.table(sleepstudy, file = "sleepstudy.txt", row.names=FALSE, col.names = 
FALSE)

r <- nparACT_flex_loop(newdir, SR = 4/60, minutes = 435)

}

setwd(wd)

}



Best,

Christine





-Ursprüngliche Nachricht-
Von: Duncan Murdoch [mailto:murdoch.dun...@gmail.com]
Gesendet: Dienstag, 19. Dezember 2017 16:19
An: Blume Christine; r-package-devel@r-project.org
Betreff: Re: [R-pkg-devel] nparACT package: "working directory was changed 
to...resetting"



On 19/12/2017 9:42 AM, Blume Christine wrote:

> Dear Community,

>

>

>

> For Fedora my package now gives a warning message when running the example:

>

>

>

> "Warning: working directory was changed to 
> '/data/gannet/ripley/R/packages/tests-clang/nparACT.Rcheck/sleepstudy_example',
>  resetting"

>

>

>

> I do not really know how to approach/solve this, what has recently been 
> changed in R devel so this error message started appearing?



Previously you were allowed to change directory in an example.  Now you're not. 
 This makes sense:  the user might not want to change the working directory.



To fix this, just save the old directory, and restore it at the end of your 
example.  For example,



   olddir <- setwd(tempdir())

   # Run the rest of the example code here

   setwd(olddir)



Duncan Murdoch



>

>

>

> The full message can be seen here:

> https://CRAN.R-project.org/web/checks/check_results_nparACT.html

>

>

>

> Any help is appreciated and rewarded with gratitude.

>

>

>

> Best,

>

>

>

> Christine

>

>

>

> [[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