Skip to content

Commit 08ec2c1

Browse files
committed
Use absolute paths instead of cd to avoid directory changes
- Calculate PROJECT_ROOT using realpath and dirname - Use R's setwd() instead of shell cd - Safer approach that doesn't change working directory
1 parent d23b2dc commit 08ec2c1

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

template/.devcontainer/checkREnvironment.sh.jinja

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@ fi
3535
echo "✅ pak is installed"
3636

3737
# Check if renv.lock exists and restore if needed
38-
if [[ -f "../renv.lock" ]]; then
38+
PROJECT_ROOT="$(dirname "$(dirname "$(realpath "$0")")")"
39+
if [[ -f "$PROJECT_ROOT/renv.lock" ]]; then
3940
echo "📦 Found renv.lock file, restoring environment..."
4041

41-
# Change to project root directory for renv operations
42-
cd ..
43-
44-
if Rscript -e "renv::restore()"; then
42+
if Rscript -e "setwd('$PROJECT_ROOT'); renv::restore()"; then
4543
echo "✅ R environment restored successfully"
4644
else
4745
echo "❌ Error: Failed to restore R environment from renv.lock"

0 commit comments

Comments
 (0)