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

Adding and Renv template #148

Closed
wants to merge 8 commits into from
Closed

Adding and Renv template #148

wants to merge 8 commits into from

Conversation

RichardJActon
Copy link
Collaborator

A new template for using the {renv} package for R package management.

@rokroskar
Copy link
Member

Hi @RichardJActon apologies for allowing this PR to go stale - I tried to initialize a project using the template just now and it complained that the 0.15.5 version of renv couldn't be found - changing to 0.16.0 (the current one afaict) didn't improve much and I got this error:

Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
trying URL 'https://cran.r-project.org/src/contrib/renv_0.16.0.tar.gz'
Content type 'application/x-gzip' length 1004572 bytes (981 KB)
==================================================
downloaded 981 KB
* installing *source* package ‘renv’ ...
** package ‘renv’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (renv)
> renv::init(force = TRUE)
Error in readLines(file, warn = FALSE) : 'con' is not a connection
Calls: <Anonymous> ... renv_json_read_default -> paste -> %||% -> read -> readLines
Traceback (most recent calls last):
9: renv::init(force = TRUE)
8: renv_init_bioconductor(bioconductor, project)
7: renv_lockfile_read(lockpath)
6: renv_json_read(text = contents)
5: renv_json_read_default(file, text)
4: paste(text %||% read(file), collapse = "\n")
3: text %||% read(file)
2: read(file)
1: readLines(file, warn = FALSE)
Execution halted

Any idea how this needs to be solved/circumvented?

One other thing that comes to mind is that a more stable source of renv needs to be considered for the template, otherwise projects will start to fail as soon as a new version is released. What other source could be used?

@RichardJActon
Copy link
Collaborator Author

Ah yes - I think I've got a fix for the renv version issue that should be robust to future version changes, I've had that problem before.
The directory structure on CRAN's servers is different for 'archival' and latest versions where archival is anything that is not the latest.

I'll see if I can get my fork cleaned up today so you can give it another look.

@rokroskar
Copy link
Member

Perfect thank you!

@rokroskar
Copy link
Member

Also, initially I thought that it would be too much to have two options for creating an R project, but after going through the motions of using this branch to make a project I think it's actually quite OK so we can merge this as is when this issue with the renv versions is cleared up.

@cmdoret do you have any opinion on whether having a dedicated Renv-based project template is a reasonable thing to do?

@RichardJActon
Copy link
Collaborator Author

I'd be happy to move it over the the community contributed repo if you'd rather keep the core set templates small and think 3 different R options is a bit much with basic R, bioc & renv I can see it causing a bit if decision paralysis in a new user. Though the tooltips do provide a decent description of the differences - whatever you think is best.

@cmdoret
Copy link
Member

cmdoret commented Nov 23, 2022

Thanks @RichardJActon this is great !
@rokroskar I agree it makes sense to provide an Renv template, but would maybe keep it in the community templates for the reason @RichardJActon mentioned.

@RichardJActon
Copy link
Collaborator Author

OK so I've changed a few things based on some improvements that I made in another project I was working on.

There is now a dedicated renv_install.sh bash script which checks the Renv versions and picks the right URL for is the renv version is latest or older. It also assumes that the project is starting with an renv.lock file which is the source of truth for the R and renv versions. If renv.lock is missing or if there is a mismatch between the container R version and the R version in the lock file the build will throw and error. I think this makes sense given a key function of renv is to ensure the environment is indeed the same. (Note this renv_install.sh script depends on jq and curl which I added as apt packages)

I've added the renv directory and the renv activation to the .Rprofile to streamline renv environment activation when the project is opened which I apparently forgot to do before.

Some other minor changes I pulled in from my other project:

  • a version of .renku/renuk.ini with comments that document it's use
  • The option to apply your RStudio config customisation
  • The librsvg2 packages are dependencies of a number of common R plotting libraries which I've added to the apt install list for convenience

Right let me fork the community templates repo and apply these changes over there - I'd appreciate it if you could give it a test and see if it's all working as intended.

@RichardJActon
Copy link
Collaborator Author

OK a PR is open over in the community templates repo now. (see above)

@@ -0,0 +1,26 @@
; Renku Config
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 maybe you could make a generic PR just with this commit for all the templates... :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will need a tweak for the Jupyter ones for the right default_url but sure I can go trough the other templates add the generic comments and check I'm not nuking anyone else custom defaults

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

Successfully merging this pull request may close these issues.

None yet

3 participants