-
Notifications
You must be signed in to change notification settings - Fork 0
Update README.md: Enhance usage instructions and add container setup details #7
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
94895a2
Update README.md: Enhance usage instructions and add container setup …
MVesuviusC d84691c
Update README.md: Improve formatting and enhance usage instructions f…
MVesuviusC 40369d3
Potential fix for pull request finding
MVesuviusC 9ce39b8
Update README.md: Clarify container usage instructions and fix bindin…
MVesuviusC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,126 @@ | ||
| # R4_4_sing_container | ||
| # R singularity/apptainer containers | ||
|
|
||
| ## Usage | ||
| Get this container using this command: | ||
| `singularity pull oras://ghcr.io/kidcancerlab/r_4_4:latest` | ||
|
|
||
| ### You can run the container using these commands | ||
|
|
||
| ```bash | ||
| # Make a workspace | ||
| cd | ||
| mkdir testrv | ||
|
|
||
| # The rv cache needs to be outside of the container and bound to it, so we make a directory for it here. | ||
| mkdir testrv/rv_cache | ||
| cd testrv | ||
|
|
||
| singularity pull oras://ghcr.io/kidcancerlab/r4_6_0:latest | ||
|
|
||
|
|
||
| singularity shell \ | ||
| --no-home \ | ||
| --bind ~/testrv:/project \ | ||
| --bind ~/testrv/rv_cache:/cache/rv \ | ||
| r4_6_0_latest.sif | ||
| ``` | ||
|
|
||
| ### inside of container | ||
|
|
||
| This is needed on our cluster because $TMPDIR is set when I request a compute node. | ||
| If $TMPDIR is set, rv will try to use it for caching and fail because it's not writable. Unsetting it allows rv to use the /cache/rv directory that we bind to the container, which is writable. | ||
| ```bash | ||
| unset TMPDIR | ||
| ``` | ||
|
|
||
| ### Then, you can initialize rv in the project directory and start adding packages to your rproject.toml file | ||
| ```bash | ||
| cd /project | ||
|
|
||
| rv init | ||
| ``` | ||
|
|
||
| update rproject.toml: | ||
| ```toml | ||
| repositories = [ | ||
| { alias = "CRAN", url = "https://cran.rstudio.com/" }, | ||
| { alias = "PPM", url = "https://packagemanager.posit.co/cran/latest" }, | ||
| { alias = "bioconductor", url = "https://bioconductor.org/packages/3.20/bioc" }, | ||
| { alias = "BioCann", url = "https://bioconductor.org/packages/3.20/data/annotation"}, | ||
| { alias = "BioCexp", url = "https://bioconductor.org/packages/3.20/data/experiment" }, | ||
| { alias = "BioCworkflows", url = "https://bioconductor.org/packages/3.20/workflows"}, | ||
| ] | ||
|
|
||
| dependencies = [ | ||
| "dplyr", | ||
| ] | ||
| ``` | ||
|
|
||
| ### Use rv to install packages | ||
| ```bash | ||
| rv plan | ||
|
|
||
| rv sync | ||
| ``` | ||
|
|
||
| ## Development | ||
| To test a container out for development purposes, you can run the container in "sandbox" mode using this command: | ||
| `singularity build --sandbox sing_sandbox oras://ghcr.io/kidcancerlab/r4_6_0:latest` | ||
|
|
||
| Then, you can run the container using these commands: | ||
| ```bash | ||
| cd | ||
| mkdir testrv | ||
| mkdir testrv/rv_cache | ||
| cd testrv | ||
|
|
||
| singularity shell \ | ||
| --no-home \ | ||
| --writable \ | ||
| --fakeroot \ | ||
| --bind ~/testrv:/project \ | ||
| --bind ~/testrv/rv_cache:/cache/rv \ | ||
| sing_sandbox | ||
|
|
||
| mkdir sing_sandbox/project | ||
| mkdir -p sing_sandbox/cache/rv | ||
| ``` | ||
|
MVesuviusC marked this conversation as resolved.
|
||
|
|
||
| This lets you install or change things in the container and test them. Then, copy the relevant commands back to the .def file. | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| ## Misc | ||
|
MVesuviusC marked this conversation as resolved.
|
||
| I'm dropping this code here for later reference. It was generated by Gemini and I have not tested it, but I like the concept. It lets you run R code inside the container directly from a Quarto document. | ||
|
|
||
|
MVesuviusC marked this conversation as resolved.
|
||
| ```{r setup, include=FALSE} | ||
| # Define a custom knitr engine | ||
| knitr::knit_engines$set(sing_r = function(options) { | ||
| # Collapse the chunk code into a single string | ||
| code <- paste(options$code, collapse = '\n') | ||
|
|
||
| # Wrap it in the apptainer command | ||
| # (Change the .sif name to match your actual container) | ||
| cmd <- sprintf("apptainer exec my_r_container.sif Rscript -e %s", shQuote(code)) | ||
|
MVesuviusC marked this conversation as resolved.
|
||
|
|
||
| # Execute the command and capture the output | ||
| out <- system(cmd, intern = TRUE) | ||
|
|
||
| # Return the properly formatted output back to Quarto | ||
| knitr::engine_output(options, options$code, out) | ||
| }) | ||
| ``` | ||
| ```{sing_r} | ||
| # do stuff inside the container | ||
| print("Hello from inside the container!") | ||
| ``` | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.