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

How to activate renv in notebook #4695

Open
petetronic opened this issue Sep 16, 2024 Discussed in #4687 · 1 comment
Open

How to activate renv in notebook #4695

petetronic opened this issue Sep 16, 2024 Discussed in #4687 · 1 comment
Labels
area: environment Issues related to Environment category. area: notebooks Issues related to Notebooks category. enhancement New feature or request lang: r support
Milestone

Comments

@petetronic
Copy link
Collaborator

Logging an issue from a discussion to consider an enhancement for renv management for notebooks in subfolders, and whether the "project" level environment should be set for those notebook sessions automatically if found.

Discussed in #4687

Originally posted by rbudnar September 14, 2024
Hi all!

My apologies if this is answered elsewhere or if I'm just missing something obvious (I'm a bit of a newcomer to R as well, coming from python). I was testing out using Jupyter notebooks in positron and I was wondering if it is possible to use the local renv for packages. Renvs work great in R scripts without me having to do anything, but in a notebook context it doesn't find my renv-installed packages (where my notebook is under the src folder). After messing around for a while, this looks like it worked inside my notebook:

setwd("..") # need to go up a directory first, otherwise renv::activate will create a new renv in the current folder
renv::activate()
.libPaths(renv::paths$library())

My question is - is there a better way to do this? Messing around with paths can get clunky, especially if I need to move things around.

Thank you!

@petetronic petetronic added lang: r area: notebooks Issues related to Notebooks category. area: environment Issues related to Environment category. labels Sep 16, 2024
@juliasilge
Copy link
Contributor

I chatted with Kevin on this and will share some details, for example on how RStudio handles rendering .Rmd (which also use their own location as the working directory):

The main thing RStudio does here is ensure that the current library paths are forwarded to the child R process invoking rmarkdown::render() via the R_LIBS environment variable, so that the library paths are “inherited” by the child process

We would want to do something that is in spirit similar to:

  • start a session from the workspace root to let renv set R_LIBS and option around repos
  • start a notebook session that inherits these values of R_LIBS, repos, etc

@juliasilge juliasilge added enhancement New feature or request support labels Sep 16, 2024
@petetronic petetronic added this to the Future milestone Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: environment Issues related to Environment category. area: notebooks Issues related to Notebooks category. enhancement New feature or request lang: r support
Projects
None yet
Development

No branches or pull requests

2 participants