Skip to content

Commit de4c719

Browse files
authored
Update R tester to allow renv.lock file upload (#581)
1 parent 5e276a5 commit de4c719

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ All notable changes to this project will be documented here.
33

44
## [unreleased]
55
- Update python, pyta and jupyter testers to allow a requirements file (#580)
6+
- Update R tester to allow a renv.lock file (#581)
67

78
## [v2.6.0]
89
- Update python versions in docker file (#568)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Script to install dependencies for R tester environment using a renv.lock file.
2+
3+
# Install renv if not already installed
4+
if (!("renv" %in% rownames(installed.packages()))) {
5+
install.packages("renv")
6+
}
7+
library(renv)
8+
9+
# Set the path for the renv.lock file and the env_dir directory
10+
lockfile <- commandArgs(trailingOnly = TRUE)[1]
11+
env_dir <- commandArgs(trailingOnly = TRUE)[2]
12+
13+
if (!file.exists(lockfile)) {
14+
stop("renv.lock file not found: ", lockfile)
15+
}
16+
17+
# Initialize the renv environment and restore dependencies from the lockfile
18+
renv::restore(lockfile = lockfile, library = env_dir)

server/autotest_server/testers/r/settings_schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
"title": "R environment",
1515
"type": "object",
1616
"properties": {
17+
"renv.lock": {
18+
"title": "Use renv to set up environment",
19+
"type": "boolean",
20+
"default": false
21+
},
1722
"requirements": {
1823
"title": "Package requirements",
1924
"type": "string"

server/autotest_server/testers/r/setup.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55

66
def create_environment(settings_, env_dir, default_env_dir):
77
env_data = settings_.get("env_data", {})
8-
req_string = env_data.get("requirements", "")
8+
lockfile_submitted = env_data.get("renv.lock", False)
99
os.makedirs(env_dir, exist_ok=True)
1010
env = {"R_LIBS_SITE": env_dir, "R_LIBS_USER": env_dir}
1111

12+
req_string = env_data.get("requirements", "")
1213
r_tester_setup = os.path.join(os.path.dirname(os.path.realpath(__file__)), "lib", "r_tester_setup.R")
1314
subprocess.run(
1415
["Rscript", r_tester_setup, req_string],
@@ -18,6 +19,17 @@ def create_environment(settings_, env_dir, default_env_dir):
1819
capture_output=True,
1920
)
2021

22+
if lockfile_submitted:
23+
renv_lock_path = os.path.join(env_dir, "../", "files", "renv.lock")
24+
r_renv_setup = os.path.join(os.path.dirname(os.path.realpath(__file__)), "lib", "r_renv_setup.R")
25+
if os.path.exists(renv_lock_path):
26+
subprocess.run(
27+
["Rscript", r_renv_setup, renv_lock_path, env_dir],
28+
env={**os.environ, **env},
29+
check=True,
30+
text=True,
31+
capture_output=True,
32+
)
2133
return {**env, "PYTHON": os.path.join(default_env_dir, "bin", "python3")}
2234

2335

0 commit comments

Comments
 (0)