Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rstudioapi::restartSession() doesn't unload packages #111

Open
burchill opened this issue Sep 19, 2018 · 2 comments
Open

rstudioapi::restartSession() doesn't unload packages #111

burchill opened this issue Sep 19, 2018 · 2 comments

Comments

@burchill
Copy link

I just noticed that when I call rstudioapi::restartSession() in the console, the packages I had loaded previously are still there. This differs from the behavior of clicking on Session > Restart R, which doesn't have the following issue.

I inputted the commands below, expecting R to throw an error when select was called for the second time, but it did not and worked the same both times.

library(dplyr)
select(data.frame(x=1,y=1), y)
rstudioapi::restartSession()
select(data.frame(x=1,y=1), y)

Additionally, after restarting the session, the follow message appeared:

Warning message:
package ‘dplyr’ was built under R version 3.3.2 

I'm using R version 3.3.1 (2016-06-21) and RStudio v. 1.1.456

@MilesMcBain
Copy link

MilesMcBain commented Mar 2, 2019

I've just reproduced this in the current R release. I think this is an important issue because the misconception that this creates a completely fresh session could lead to unexpected reproducibility failures.

Edit: I've just discovered that restartSession() preserves the environment:

> a <- 1
> rstudioapi::restartSession()

Restarting R session...

> a
[1] 1
> 

This is completely unexpected to me, to the point where I am no longer sure what the usecase of this function is. Is this function named in a misleading way?

> sessionInfo()
R version 3.5.2 (2018-12-20)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 9 (stretch)

Matrix products: default
BLAS: /usr/lib/openblas-base/libblas.so.3
LAPACK: /usr/lib/libopenblasp-r0.2.19.so

locale:
 [1] LC_CTYPE=en_AU.UTF-8       LC_NUMERIC=C               LC_TIME=en_AU.UTF-8       
 [4] LC_COLLATE=en_AU.UTF-8     LC_MONETARY=en_AU.UTF-8    LC_MESSAGES=en_AU.UTF-8   
 [7] LC_PAPER=en_AU.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rstudioapi_0.9.0

loaded via a namespace (and not attached):
[1] compiler_3.5.2 tools_3.5.2    packrat_0.5.0 

@mlell
Copy link

mlell commented Oct 21, 2024

As of RStudio 2024.09.0 & rstudioapi 0.16.0 (my versions, probably earlier), restartSession(clean = TRUE) shows the intended behaviour. (See rstudio/rstudio#2841)

library(dplyr)
select(data.frame(x=1,y=1), y)
##    y
## 1 1
rstudioapi::restartSession()

## Restarting R session...

select(data.frame(x=1,y=1), y)
##   y
## 1 1
 
rstudioapi::restartSession(clean = TRUE)
## Restarting R session...
select(data.frame(x=1,y=1), y)
## Error in select(data.frame(x = 1, y = 1), y) : 
##   could not find function "select"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants