Skip to content

.Rprofile sourcing to include ~ when initializing rv globally #203

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 3 commits into from
Apr 14, 2025

Conversation

wes-a2ai
Copy link
Contributor

@wes-a2ai wes-a2ai commented Apr 7, 2025

No description provided.

@wes-a2ai
Copy link
Contributor Author

wes-a2ai commented Apr 7, 2025

wes@ip-10-2-72-104:~$ cargo run --all-features --manifest-path=projects/rv/Cargo.toml -- init
   Compiling rv v0.4.0 (/cluster-data/user-homes/wes/projects/rv)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 4.01s
     Running `projects/rv/target/debug/rv init`
rv project successfully initialized at .
wes@ip-10-2-72-104:~$ cat .Rprofile 
source("~/rv/scripts/rvr.R")
source("~/rv/scripts/activate.R")
wes@ip-10-2-72-104:~$ cat ~/rv/scripts/activate.R 
local({
        owd <- getwd()
        setwd("~")
        on.exit({
            setwd(owd)
        })
        rv_info <- system2("rv", c("info", "--library", "--r-version", "--repositories"), stdout = TRUE)
        ... parsing and setting ....
)}

@wes-a2ai
Copy link
Contributor Author

wes-a2ai commented Apr 7, 2025

wes@ip-10-2-72-104:~$ cargo run --all-features --manifest-path=projects/rv/Cargo.toml -- deactivate
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.08s
     Running `projects/rv/target/debug/rv deactivate`
rv deactivated
wes@ip-10-2-72-104:~$ cat ~/.Rprofile <printed nothing since its empty>

@wes-a2ai wes-a2ai changed the title include home dir to .Rprofile when using rv globally .Rprofile sourcing to include ~ when initializing rv globally Apr 7, 2025
@wes-a2ai wes-a2ai requested a review from dpastoor April 7, 2025 16:05
@wes-a2ai wes-a2ai linked an issue Apr 7, 2025 that may be closed by this pull request
Copy link
Member

@dpastoor dpastoor left a comment

Choose a reason for hiding this comment

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

one question about the ref but otherwise looks reasonable.

can you throw some evidence of using it, then starting R from a different directory (such that it still hits that global Rprofile, and seeing things activate correctly

src/activate.rs Outdated
@@ -97,7 +114,7 @@ fn write_activate_file(dir: impl AsRef<Path>) -> Result<(), ActivateError> {
.replace("%global wd content%", global_wd_content);
// read the file and determine if the content within the activate file matches
// File may exist but needs upgrade if file changes with rv upgrade
let activate_file_name = &dir.join(ACTIVATE_FILE_NAME);
let activate_file_name = &dir.as_ref().join(ACTIVATE_FILE_NAME);
Copy link
Member

Choose a reason for hiding this comment

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

isn't &dir a ref itself, so why another as_ref()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

impl AsRef<Path> --.as_ref()--> &Path --.join()--> PathBuf

So I have &dir to get &PathBuf, but realized I should just own it here and then use references on 121 and 127

@wes-a2ai
Copy link
Contributor Author

wes@ip-10-2-72-104:~/projects/rv$ cargo run --all-features -- init ../..
   Compiling rv v0.4.0 (/cluster-data/user-homes/wes/projects/rv)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 9.77s
     Running `target/debug/rv init ../..`
rv project successfully initialized at ../..
wes@ip-10-2-72-104:~/projects/rv$ cd ~
wes@ip-10-2-72-104:~$ mkdir rv-test
wes@ip-10-2-72-104:~$ cd rv-test
wes@ip-10-2-72-104:~/rv-test$ R

R version 4.4.1 (2024-06-14) -- "Race for Your Life"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

creating rv library: rv/library/4.4/x86_64/jammy
rv libpaths active!
library paths: 
  /cluster-data/user-homes/wes/rv/library/4.4/x86_64/jammy
  /opt/R/4.4.1/lib/R/library

rv repositories active!
repositories: 
  RSPM: https://packagemanager.posit.co/cran/2024-10-06
  gh-pkg-mirror: https://a2-ai.github.io/gh-pkg-mirror/2024-10-06

@wes-a2ai wes-a2ai merged commit 5f38fe9 into main Apr 14, 2025
6 checks passed
@wes-a2ai wes-a2ai deleted the home-init branch April 14, 2025 13:32
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.

rv in home dir should also source ~/rv
2 participants