From ad3e8f2a27be0c90fb19f66a794de565b562514b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Mon, 24 Jan 2022 15:50:17 +0100 Subject: [PATCH 01/11] Bump to (dev) 0.1.5 version --- Cargo.toml | 2 +- NEWS.md | 4 ++++ README.md | 5 ++++- src/args.rs | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c9d0e76..c2af05d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rim" -version = "0.1.4" +version = "0.1.5" edition = "2021" authors = ["Gábor Csárdi App<'static> { let rim = App::new("RIM -- The R Installation Manager") - .version("0.1.4") + .version("0.1.5") .about(HELP_ABOUT) .setting(AppSettings::ArgRequiredElseHelp) .term_width(80); From 333719940913e9f85bc9360727afaddbb489c392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Mon, 24 Jan 2022 15:59:53 +0100 Subject: [PATCH 02/11] Use Rmd for README --- Makefile | 5 +- README.Rmd | 80 +++++++++++++++++ README.md | 253 ++++++++++++++++++++++++++--------------------------- 3 files changed, 206 insertions(+), 132 deletions(-) create mode 100644 README.Rmd diff --git a/Makefile b/Makefile index 5d413e9..87a7da7 100644 --- a/Makefile +++ b/Makefile @@ -57,7 +57,10 @@ rim-unnotarized-%.pkg: build.stamp distribution.xml.in --version $(VERSION) \ --sign "Developer ID Installer: Gabor Csardi" $@ -build.stamp: target/release/rim target/x86_64-apple-darwin/release/rim +README.md: README.Rmd + R -q -e 'rmarkdown::render("README.Rmd")' + +build.stamp: target/release/rim target/x86_64-apple-darwin/release/rim README.md rm -rf build-arm64 build-x86_64 # arm64 mkdir -p build-arm64/usr/local/bin diff --git a/README.Rmd b/README.Rmd new file mode 100644 index 0000000..304d4e2 --- /dev/null +++ b/README.Rmd @@ -0,0 +1,80 @@ +--- +output: github_document +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + comment = "#>", + out.width = "100%" +) +``` + +# The R Installation Manager + +Install, remove, configure R versions. + +## 🚀  Features + +* Works on macOS and Windows. Linux version is coming soon! +* Install multiple R versions, select the default one, run multiple + versions at the same time using quick links. E.g. `R-4.1` starts + R 4.1.x. +* Select R version to install using symbolic names: `devel`, `release`, + `oldrel` and more. +* On M1 macs select between x86_64 and arm64 versions or R, or install both. +* Makes sure that installed packages are kept separete from the R + installation. +* Includes auto-complete for `zsh` and `bash`. +* Installs Rtools on Windows. + +## ⬇️  Installation + +Download the latest release from https://github.com/gaborcsardi/rim/releases. + +### Auto-complete + +The macOS installer and also installs the `zsh` and `bash` completions. +`zsh` completions work out of the box. +For `bash` completions install the `bash-completion` package from Homebrew +and make sure it is loaded from your `.bashrc`. (You don't need to install +`bash` from Homebrew, but you can if you like.) + +## ⚙️  Usage + +Use `rim add` to add a new R installation: + +``` +rim add release +``` + +Use `rim list` to list the currently installed R versions, and `rim default` +to set the default one. + +Run `rim` to see all commands and examples: + +```{bash, eval = FALSE} +rim +``` + +```{bash, echo = FALSE, error = TRUE} +./target/release/rim +``` + +Run `rim --help` for information about a subcommand: + +```{bash, eval = FALSE} +rim default --help +``` + +```{bash, echo = FALSE} +./target/release/rim default --help +``` + +## 🤝  Feedback + +Please open an issue in our issue tracker at +https://github.com/gaborcsardi/rim/issues + +## 📘  License + +MIT 2021-2022 © RStudio Pbc. diff --git a/README.md b/README.md index ab46c03..6653255 100644 --- a/README.md +++ b/README.md @@ -3,159 +3,150 @@ Install, remove, configure R versions. -## 🚀  Features - -* Works on macOS and Windows. Linux version is coming soon! -* Install multiple R versions, select the default one, run multiple - versions at the same time using quick links. E.g. `R-4.1` starts - R 4.1.x. -* Select R version to install using symbolic names: `devel`, `release`, - `oldrel` and more. -* On M1 macs select between x86_64 and arm64 versions or R, or install both. -* Makes sure that installed packages are kept separete from the R - installation. -* Includes auto-complete for `zsh` and `bash`. -* Installs Rtools on Windows. - -## ⬇️  Installation - -Download the latest release from https://github.com/gaborcsardi/rim/releases. +## 🚀  Features + +- Works on macOS and Windows. Linux version is coming soon! +- Install multiple R versions, select the default one, run multiple + versions at the same time using quick links. E.g. `R-4.1` starts R + 4.1.x. +- Select R version to install using symbolic names: `devel`, + `release`, `oldrel` and more. +- On M1 macs select between x86_64 and arm64 versions or R, or install + both. +- Makes sure that installed packages are kept separete from the R + installation. +- Includes auto-complete for `zsh` and `bash`. +- Installs Rtools on Windows. + +## ⬇️  Installation + +Download the latest release from +. ### Auto-complete The macOS installer and also installs the `zsh` and `bash` completions. -`zsh` completions work out of the box. -For `bash` completions install the `bash-completion` package from Homebrew -and make sure it is loaded from your `.bashrc`. (You don't need to install -`bash` from Homebrew, but you can if you like.) +`zsh` completions work out of the box. For `bash` completions install +the `bash-completion` package from Homebrew and make sure it is loaded +from your `.bashrc`. (You don’t need to install `bash` from Homebrew, +but you can if you like.) -## ⚙️  Usage +## ⚙️  Usage Use `rim add` to add a new R installation: -``` -rim add release -``` + rim add release -Use `rim list` to list the currently installed R versions, and `rim default` -to set the default one. +Use `rim list` to list the currently installed R versions, and +`rim default` to set the default one. Run `rim` to see all commands and examples: -``` +``` bash rim ``` -``` -RIM -- The R Installation Manager 0.1.0 - -DESCRIPTION - rim manages your R installations, on macOS and Windows. It can install - and set up multiple versions R, and it makes sure that they work - together. - - On macOS R versions installed by rim do not interfere. You can run multiple - versions at the same time. rim also makes sure that packages installed by - the user go into a user package library, so reinstalling R will not wipe - out your installed packages. - - rim is currently work in progress. Feedback is appreciated. - See https://github.com/gaborcsardi/rim for bug reports and more. - -USAGE: - rim [SUBCOMMAND] - -FLAGS: - -h, --help Prints help information - -V, --version Prints version information - -SUBCOMMANDS: - add Install a new R version - available List R versions available to install (TODO) - default Print or set default R version - help Prints this message or the help of the given subcommand(s) - list List installed R versions - resolve Resolve a symbolic R version - rm Remove R versions - system Manage current installations - -EXAMPLES: - # Add the latest development snapshot - rim add devel - - # Add the latest release - rim add release - - # Install specific version - rim add 4.1.2 - - # Install latest version within a minor branch - rim add 4.1 - - # List installed versions - rim list - - # Set default version - rim default 4.0 -``` + #> RIM -- The R Installation Manager 0.1.4 + #> NAME + #> rim - manage R installations + #> + #> DESCRIPTION + #> rim manages your R installations, on macOS and Windowss It can install + #> and set up multiple versions R, and make sure that they work together. + #> + #> On macOS R versions installed by rim do not interfere. You can run multiple + #> versions at the same time. rim also makes sure that packages installed by + #> the user go into a user package library, so reinstalling R will not wipe + #> out your installed packages. + #> + #> rim is currently work in progress. Feedback is appreciated. + #> See https://github.com/gaborcsardi/rim for bug reports and more. + #> + #> USAGE: + #> rim [SUBCOMMAND] + #> + #> OPTIONS: + #> -h, --help Print help information + #> -V, --version Print version information + #> + #> SUBCOMMANDS: + #> add Install a new R version + #> default Print or set default R version + #> help Print this message or the help of the given subcommand(s) + #> list List installed R versions + #> resolve Resolve a symbolic R version + #> rm Remove R versions + #> system Manage current installations + #> + #> EXAMPLES: + #> # Add the latest development snapshot + #> rim add devel + #> + #> # Add the latest release + #> rim add release + #> + #> # Install specific version + #> rim add 4.1.2 + #> + #> # Install latest version within a minor branch + #> rim add 4.1 + #> + #> # List installed versions + #> rim list + #> + #> # Set default version + #> rim default 4.0 Run `rim --help` for information about a subcommand: -``` +``` bash rim default --help ``` -``` -rim-default - -DESCRIPTION - Print or set the default R version. The default R version is the one that - is started with the `R` command, usually via the `/usr/local/bin/R` - symbolic link. - - Call without any arguments to see the current default. Call with the - version number/name to set the default. Before setting a default, you - can call `rim list` to see the installed R versions. - - The default R version is set by updating the symbolic link at - `/Library/Frameworks/R.framework/Versions/Current` and pointing it to the - specified R version. - - Potentially you need to run this command with `sudo` to change the - default version: `sudo rim default ...`. - - You don't need to update the default R version to just run a non-default R - version. You can use the `R-` links, see `rim system make-links`. - -USAGE: - rim default [version] - -FLAGS: - -h, --help - Prints help information - - -V, --version - Prints version information - - -ARGS: - - new default R version to set - - -EXAMPLES: - # Query default R version - rim default - - # Set the default version - rim default 4.1 -``` - -## 🤝  Feedback + #> rim-default + #> + #> DESCRIPTION: + #> Print or set the default R version. The default R version is the one that + #> is started with the `R` command, usually via the `/usr/local/bin/R` + #> symbolic link. + #> + #> Call without any arguments to see the current default. Call with the + #> version number/name to set the default. Before setting a default, you + #> can call `rim list` to see the installed R versions. + #> + #> The default R version is set by updating the symbolic link at + #> `/Library/Frameworks/R.framework/Versions/Current` and pointing it to the + #> specified R version. + #> + #> Potentially you need to run this command with `sudo` to change the + #> default version: `sudo rim default ...`. + #> + #> You don't need to update the default R version to just run a non-default R + #> version. You can use the `R-` links, see `rim system make-links`. + #> + #> USAGE: + #> rim default [version] + #> + #> ARGS: + #> + #> new default R version to set + #> + #> OPTIONS: + #> -h, --help + #> Print help information + #> + #> EXAMPLES: + #> # Query default R version + #> rim default + #> + #> # Set the default version + #> rim default 4.1 + +## 🤝  Feedback Please open an issue in our issue tracker at -https://github.com/gaborcsardi/rim/issues + -## 📘  License +## 📘  License -MIT 2021 © RStudio Pbc. +MIT 2021-2022 © RStudio Pbc. From ae673747b214fbc31841be1312c974766b6bbb02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Mon, 24 Jan 2022 19:51:10 +0100 Subject: [PATCH 03/11] Windows: add rtools to R's path --- src/windows.rs | 52 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/src/windows.rs b/src/windows.rs index 2b61b3b..5db4747 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -1,6 +1,7 @@ #![cfg(target_os = "windows")] use std::fs::File; +use std::fs::OpenOptions; use std::io::{BufRead, BufReader}; use std::io::Write; use std::path::Path; @@ -36,7 +37,7 @@ pub fn sc_add(args: &ArgMatches) { system_create_lib(None); sc_system_make_links(); - // TODO: patch for Rtools + patch_for_rtools(); } fn add_rtools(version: String) { @@ -74,6 +75,55 @@ fn add_rtools(version: String) { } } +fn patch_for_rtools() { + let vers = sc_get_list(); + let base = Path::new(R_ROOT); + + for ver in vers { + let rtools4 = &ver[0..1] == "4"; + let envfile = base + .join("R-".to_string() + &ver) + .join("etc") + .join("Renviron.site"); + let mut ok = envfile.exists(); + if ok { + ok = false; + let file = File::open(&envfile).unwrap(); + let reader = BufReader::new(file); + for line in reader.lines() { + let line2 = line.unwrap(); + if line2.len() >= 14 && &line2[0..14] == "# added by rim" { + ok = true; + break; + } + } + } + if !ok { + let mut file = OpenOptions::new() + .create(true) + .write(true) + .append(true) + .open(&envfile) + .unwrap(); + + let head = "\n".to_string() + + "# added by rim, do not update by hand-----\n"; + let tail = "\n".to_string() + + "# ----------------------------------------\n"; + let txt3 = head.to_owned() + + "PATH=\"C:\\Rtools\\bin;${PATH}\"" + + &tail; + let txt4 = head.to_owned() + + "PATH=\"${RTOOLS40_HOME}\\ucrt64\\bin;${RTOOLS40_HOME}\\usr\\bin;${PATH}\"" + + &tail; + + if let Err(e) = writeln!(file, "{}", if rtools4 { txt4 } else { txt3 }) { + eprintln!("Couldn't write to Renviron.site file: {}", e); + } + } + } +} + fn get_rtools_needed() -> Vec { let vers = sc_get_list(); let mut res: Vec = vec![]; From 3625cb48805e252295db3b8ff178d978c5563919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Mon, 24 Jan 2022 20:12:57 +0100 Subject: [PATCH 04/11] Fix version parsing on Windows --- Cargo.lock | 2 +- src/windows.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 771b4e6..d091979 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -853,7 +853,7 @@ dependencies = [ [[package]] name = "rim" -version = "0.1.4" +version = "0.1.5" dependencies = [ "clap", "clap_complete", diff --git a/src/windows.rs b/src/windows.rs index 5db4747..358a6d7 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -19,7 +19,7 @@ const R_ROOT: &str = "C:\\Program Files\\R"; #[warn(unused_variables)] pub fn sc_add(args: &ArgMatches) { let str = args.value_of("str").unwrap().to_string(); - if &str[0..6] == "rtools" { + if str.len() >= 6 && &str[0..6] == "rtools" { return add_rtools(str); } let (version, target) = download_r(&args); @@ -49,7 +49,7 @@ fn add_rtools(version: String) { } let client = &reqwest::Client::new(); for ver in vers { - let rtools4 = &ver[0..1] == "4"; + let rtools4 = &ver[0..1] == "4" || ver == "devel"; let filename = if rtools4 { format!("rtools{}-x86_64.exe", ver) } else { @@ -80,7 +80,7 @@ fn patch_for_rtools() { let base = Path::new(R_ROOT); for ver in vers { - let rtools4 = &ver[0..1] == "4"; + let rtools4 = &ver[0..1] == "4" || ver == "devel"; let envfile = base .join("R-".to_string() + &ver) .join("etc") From fb6504a7875a37098cdb562cdbacab4366441e3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Tue, 25 Jan 2022 10:36:56 +0100 Subject: [PATCH 05/11] clap_complete is build-time only --- Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index c2af05d..d847e4e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,6 @@ categories = ["command-line-utilities"] [dependencies] clap = "3.0.10" -clap_complete = "3.0.4" futures = "0.3.17" futures-util = "0.3.14" lazy_static = "1.3.0" From 0b4d3dc83c18a7ac205cc0ab779594e1aa9c5b3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Tue, 25 Jan 2022 11:18:46 +0100 Subject: [PATCH 06/11] Better make rules for README Update if src/help-* changes, make use rim is built. --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 87a7da7..f0d360f 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ VERSION=$(shell grep "^version" Cargo.toml | tr -cd '0-9.') -SOURCES=$(wildcard src/*.rs) +SOURCES=$(wildcard src/*.rs) $(wildcard src/*.in) all: @echo "Call 'make win' or 'make macos'" @@ -57,7 +57,8 @@ rim-unnotarized-%.pkg: build.stamp distribution.xml.in --version $(VERSION) \ --sign "Developer ID Installer: Gabor Csardi" $@ -README.md: README.Rmd +README.md: README.Rmd $(SOURCES) + cargo build --release R -q -e 'rmarkdown::render("README.Rmd")' build.stamp: target/release/rim target/x86_64-apple-darwin/release/rim README.md From 0f5d0acfe30888755f17656e8eaae11306638740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Tue, 25 Jan 2022 11:19:25 +0100 Subject: [PATCH 07/11] Improve help --- README.md | 18 +++---- src/help-macos.in | 36 +++++++------- src/help-windows.in | 118 ++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 136 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 6653255..b1e0f04 100644 --- a/README.md +++ b/README.md @@ -46,21 +46,21 @@ Run `rim` to see all commands and examples: rim ``` - #> RIM -- The R Installation Manager 0.1.4 + #> RIM -- The R Installation Manager 0.1.5 #> NAME #> rim - manage R installations #> #> DESCRIPTION - #> rim manages your R installations, on macOS and Windowss It can install + #> rim manages your R installations, on macOS and Windows. It can install #> and set up multiple versions R, and make sure that they work together. #> - #> On macOS R versions installed by rim do not interfere. You can run multiple - #> versions at the same time. rim also makes sure that packages installed by - #> the user go into a user package library, so reinstalling R will not wipe - #> out your installed packages. + #> On macOS, R versions installed by rim do not interfere. You can run + #> multiple versions at the same time. rim also makes sure that packages + #> are installed into a user package library, so reinstalling R will not + #> wipe out your installed packages. #> - #> rim is currently work in progress. Feedback is appreciated. - #> See https://github.com/gaborcsardi/rim for bug reports and more. + #> rim is currently experimental and work in progress. Feedback is much + #> appreciated. See https://github.com/gaborcsardi/rim for bug reports. #> #> USAGE: #> rim [SUBCOMMAND] @@ -108,7 +108,7 @@ rim default --help #> DESCRIPTION: #> Print or set the default R version. The default R version is the one that #> is started with the `R` command, usually via the `/usr/local/bin/R` - #> symbolic link. + #> symbolic link. #> #> Call without any arguments to see the current default. Call with the #> version number/name to set the default. Before setting a default, you diff --git a/src/help-macos.in b/src/help-macos.in index c69f145..8bd5f53 100644 --- a/src/help-macos.in +++ b/src/help-macos.in @@ -8,21 +8,21 @@ const HELP_ABOUT: &str = r#"NAME rim - manage R installations DESCRIPTION - rim manages your R installations, on macOS and Windowss It can install + rim manages your R installations, on macOS and Windows. It can install and set up multiple versions R, and make sure that they work together. - On macOS R versions installed by rim do not interfere. You can run multiple - versions at the same time. rim also makes sure that packages installed by - the user go into a user package library, so reinstalling R will not wipe - out your installed packages. + On macOS, R versions installed by rim do not interfere. You can run + multiple versions at the same time. rim also makes sure that packages + are installed into a user package library, so reinstalling R will not + wipe out your installed packages. - rim is currently work in progress. Feedback is appreciated. - See https://github.com/gaborcsardi/rim for bug reports and more. + rim is currently experimental and work in progress. Feedback is much + appreciated. See https://github.com/gaborcsardi/rim for bug reports. "#; const HELP_RESOLVE: &str = r#" DESCRIPTION - Resolve R versions. Check the version number of an R version (e.g. + Resolve R versions. Checks the version number of an R version (e.g. release, devel, etc.), and looks up the URL of the installer for it, if an installer is available. @@ -61,7 +61,7 @@ const HELP_DEFAULT: &str = r#" DESCRIPTION: Print or set the default R version. The default R version is the one that is started with the `R` command, usually via the `/usr/local/bin/R` - symbolic link. + symbolic link. Call without any arguments to see the current default. Call with the version number/name to set the default. Before setting a default, you @@ -88,7 +88,7 @@ const HELP_DEFAULT_EXAMPLES: &str = r#"EXAMPLES: const HELP_LIST: &str = r#" DESCRIPTION: - List installed R versions from `/Library/Framework/R.framework/versions`. + List installed R versions from `/Library/Framework/R.framework/Versions`. It does _not_ check if they are working properly. "#; @@ -99,10 +99,10 @@ DESCRIPTION: same minor branch, see below. NOTE: it is best to quit from all currently running R sessions before - adding new R versions. THe newly added R version will be the default - after the installation, if you don't want that, call `rim default`. + adding new R versions. The newly added R version will be the default + after the installation. If you don't want that, call `rim default`. - The newly added version can be specified in various ways: + The desired R version can be specified in various ways: - `rim add devel` adds the latest available development version, - `rim add release` adds the latest release. - `rim add x.y.z` adds a specific version. @@ -145,7 +145,7 @@ const HELP_ADD_EXAMPLES: &str = r#"EXAMPLES: const HELP_RM: &str = r#" DESCRIPTION: Remove an R installation. It keeps the users' package libraries. - It automatically calls `rm system forget` before removing the files. + It automatically calls `rim system forget` before removing the files. Usually you need to run this command with `sudo`: `sudo rim rm ...`. "#; @@ -178,7 +178,7 @@ DESCRIPTION: const HELP_SYSTEM_LINKS: &str = r#" DESCRIPTION: Create quick links in `/usr/local/bin` for the current R installations. - This lets you directly run a specific R version. E.g. `R-4.1` will start + These let you directly run a specific R version. E.g. `R-4.1` will start R 4.1.x. `rim add` runs `rim system make-links`, so if you only use rim to @@ -190,7 +190,8 @@ DESCRIPTION: const HELP_SYSTEM_LIB: &str = r#" DESCRIPTION: Create directories for the current user's package libraries, for all - current R versions. + current R versions. It is better to keep packages in a user library, + because then they are not wiped out by a minor R (re)install. `rim add` runs `rim system create-lib`, so if you only use rim to install R, then you do not need to run it manually. @@ -212,6 +213,8 @@ const HELP_SYSTEM_FIXPERMS: &str = r#" DESCRIPTION: Update the permissions of the current R versions, so only the administrator can install R packages into the system library. + Together with `rim system create-lib` this facilitates keeping + additional packages in a user library, instead of the system library. `rim add` runs `rim system fix-permissions`, so if you only use rim to install R, then you do not need to run it manually. @@ -230,4 +233,3 @@ DESCRIPTION: This command probably needs `sudo`: `sudo rim system forget`. "#; - diff --git a/src/help-windows.in b/src/help-windows.in index 751564c..79104c8 100644 --- a/src/help-windows.in +++ b/src/help-windows.in @@ -9,6 +9,9 @@ DESCRIPTION rim manages your R installations, on macOS and Windows. It can install and set up multiple versions R, and it makes sure that they work together. + + rim is currently experimental and work in progress. Feedback is much + appreciated. See https://github.com/gaborcsardi/rim for bug reports. "#; const HELP_RESOLVE: &str = r#" @@ -16,11 +19,57 @@ DESCRIPTION: Resolve R versions. Check the version number of an R version (e.g. release, devel, etc.), and looks up the URL of the installer for it, if an installer is available. + + It prints the R version number, and after a space the URL of the + installer. If no installer is available for this R version and the + current platform, the URL is `NA`. + + An R version can be specified in various ways: + - `rim resolve devel` is the latest available development version, + - `rim resolve release` is the latest release. + - `rim resolve x.y.z` is a specific version. + - `rim resolve x.y` is the latest release within the `x.y` minor branch. + - `rim resolve oldrel/n` is the latest release within the `n`th previous + minor branch (`oldrel` is the same as `oldrel/1`). +"#; + +const HELP_RESOLVE_EXAMPLES: &str = r#"EXAMPLES: + # Latest development snapshot + rim resolve devel + + # Latest release (that has an installer available) + rim resolve release + + # URL for a specific version + rim resolve 4.1.2 + + # Latest version within a minor branch + rim resolve 4.1 "#; const HELP_DEFAULT: &str = r#" DESCRIPTION - Print or set the default R version. + Print or set the default R version. The default R version is the one + that can be started with the `R` and `RD` commands, via quick + batch files at `C:\Program Files\R\bin`. + + Call without any arguments to see the current default. Call with the + version number/name to set the default. Before setting a default, you + can call `rim list` to see the installed R versions. + + Potentially you need to run this command from an admininstrator shell + to change the current default. + + You don't need to update the default R version to just run a non-default R + version. You can use the `R-` links, see `rim system make-links`. + +KNOWN ISSUES: + - If you don't call `rim system default ` to set the default R + version then there is no default, and there are no `R` and `RD` + commands. + - If you delete the default R version with `rim rm` or another way, + then the `R` and `RD` commands will kept, but they will point to a + non-existing directory and fail. "#; const HELP_DEFAULT_EXAMPLES: &str = r#"EXAMPLES: @@ -28,7 +77,7 @@ const HELP_DEFAULT_EXAMPLES: &str = r#"EXAMPLES: rim default # Set the default version - rim default 4.1.2 + rim default 4.1 "#; const HELP_LIST: &str = r#" @@ -37,15 +86,43 @@ DESCRIPTION It does _not_ check if they are working properly. "#; -const HELP_RESOLVE_EXAMPLES: &str = r#"EXAMPLES: - # Latest development snapshot - rim resolve devel -"#; - const HELP_ADD: &str = r#" DESCRIPTION Download and install an R version, from the official sources. It keeps the already installed R versions. + + The desired R version can be specified in various ways: + - `rim add devel` adds the latest available development version, + - `rim add release` adds the latest release. + - `rim add x.y.z` adds a specific version. + - `rim add x.y` adds the latest release within the `x.y` minor branch. + - `rim add oldrel/n` adds the latest release within the `n`th previous + minor branch (`oldrel` is the same as `oldrel/1`). + - `rim add ` uses a `.pkg` installer from ``. + + `rim add` will call the following rim command after the installation, + to set up the newly installed version: + - `rim system create-lib` + - `rim system make-links` + See their help pages for details. + + It will also update the sytem profile of all installed versions to add + the appropriate versions of Rtools to the system PATH. + + You can use `rim add` to install Rtools: + + rim add rtools + + will install all Rtools versions that are needed for the currently + installed R versions. You can also request a specific Rtools version, + e.g. `rim add rtools40`. Rtools versions 3.x all install to `C:\Rtools`, + so only one of them can be installed at a time. + + Usually you need to run this command from an administrator shell. + + KNOWN ISSUE: + - Rtools installation will fail if the same version of Rtools is + already installed. "#; const HELP_ADD_EXAMPLES: &str = r#"EXAMPLES @@ -60,11 +137,22 @@ const HELP_ADD_EXAMPLES: &str = r#"EXAMPLES # Install latest version within a minor branch rim add 4.1 + + # Install all needed Rtools versions + rim add rtools "#; const HELP_RM: &str = r#" DESCRIPTION Remove an R installation. It keeps the users' package libraries. + + Usually you need to run this command from an administrator shell. + +KNOWN ISSUE: + - `rim rm` currently does not remove quick link + (see `rim system make-links`) for the deleted R version. + - `rim rm` does not remove the deleted R version from the system + registry currently. "#; const HELP_SYSTEM: &str = r#" @@ -77,16 +165,26 @@ const HELP_SYSTEM_LINKS: &str = r#" DESCRIPTION Create quick links in `C:\Program Files\R\bin` for the current R installations. This lets you directly run a specific R version. E.g. - `R-4.1` will start R 4.1.x. + `R-4.1.2` will start R 4.1.2. + + It also adds an `R` and `RD` link that runs the default R version. + See `rim default`. `rim add` runs `rim system make-links`, so if you only use rim to install R, then you do not need to run it manually. + + Usually you need to run this command from an administrator shell. + +KNOWN ISSUE: + - `rim system make-links` currently does not remove the links that + are not in use. "#; const HELP_SYSTEM_LIB: &str = r#" DESCRIPTION Create directories for the current user's package libraries, for all - current R versions. + current R versions. It is better to keep packages in a user library, + because then they are not wiped out by a minor R (re)install. `rim add` runs `rim system create-lib`, so if you only use rim to install R, then you do not need to run it manually. @@ -101,5 +199,5 @@ DESCRIPTION * If one or more R versions are specified, then it installs pak for those. * If no R versions are specified, then it installs pak for the default - R installation (see `rim default`). + R installation, if there is one (see `rim default`). "#; From cecf2e783fe56bf92145248c2bfd778d09631e40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Tue, 25 Jan 2022 11:27:52 +0100 Subject: [PATCH 08/11] Implement system add-pak for Windows --- src/windows.rs | 54 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/src/windows.rs b/src/windows.rs index 358a6d7..4b82bdd 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -1,5 +1,6 @@ #![cfg(target_os = "windows")] +use regex::Regex; use std::fs::File; use std::fs::OpenOptions; use std::io::{BufRead, BufReader}; @@ -184,7 +185,58 @@ pub fn sc_rm(args: &ArgMatches) { } pub fn sc_system_add_pak(args: &ArgMatches) { - unimplemented!(); + let devel = args.is_present("devel"); + let all = args.is_present("all"); + let vers = args.values_of("version"); + if all { + system_add_pak(Some(sc_get_list()), devel); + } else if vers.is_none() { + system_add_pak(None, devel); + return; + } else { + let vers: Vec = vers.unwrap().map(|v| v.to_string()).collect(); + system_add_pak(Some(vers), devel); + } +} + +fn system_add_pak(vers: Option>, devel: bool) { + let vers = match vers { + Some(x) => x, + None => vec![sc_get_default()], + }; + + let base = Path::new(R_ROOT); + let re = Regex::new("[{][}]").unwrap(); + let stream = if devel { "devel" } else { "stable" }; + + for ver in vers { + println!("Installing pak for R {}", ver); + check_installed(&ver); + let r = base + .join("R-".to_string() + &ver) + .join("bin") + .join("R.exe"); + let r = r.to_str().unwrap(); + let cmd = r#" + dir.create(Sys.getenv('R_LIBS_USER'), showWarnings = FALSE, recursive = TRUE); + install.packages('pak', repos = 'https://r-lib.github.io/p/pak/{}/') + "#; + let cmd = re.replace(cmd, stream).to_string(); + let cmd = Regex::new("[\n\r]") + .unwrap() + .replace_all(&cmd, "") + .to_string(); + let status = Command::new(r) + .args(["--vanilla", "-s", "-e", &cmd]) + .spawn() + .expect("Failed to run R to install pak") + .wait() + .expect("Failed to run R to install pak"); + + if !status.success() { + panic!("Failed to run R {} to install pak", ver); + } + } } pub fn system_create_lib(vers: Option>) { From 9b6f71db68b6f94d5e7567b987cf4619f630e7d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Tue, 25 Jan 2022 11:30:13 +0100 Subject: [PATCH 09/11] Help typo --- src/help-windows.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/help-windows.in b/src/help-windows.in index 79104c8..9eb4805 100644 --- a/src/help-windows.in +++ b/src/help-windows.in @@ -120,7 +120,7 @@ DESCRIPTION Usually you need to run this command from an administrator shell. - KNOWN ISSUE: +KNOWN ISSUE: - Rtools installation will fail if the same version of Rtools is already installed. "#; From f5af373696507f286090ce21a127480f6b150c25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Tue, 25 Jan 2022 11:50:35 +0100 Subject: [PATCH 10/11] Win: RS quick link Not RD, because that is a powershell command. --- src/help-windows.in | 8 ++++---- src/windows.rs | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/help-windows.in b/src/help-windows.in index 9eb4805..cf162bd 100644 --- a/src/help-windows.in +++ b/src/help-windows.in @@ -50,7 +50,7 @@ const HELP_RESOLVE_EXAMPLES: &str = r#"EXAMPLES: const HELP_DEFAULT: &str = r#" DESCRIPTION Print or set the default R version. The default R version is the one - that can be started with the `R` and `RD` commands, via quick + that can be started with the `R` and `RS` commands, via quick batch files at `C:\Program Files\R\bin`. Call without any arguments to see the current default. Call with the @@ -65,10 +65,10 @@ DESCRIPTION KNOWN ISSUES: - If you don't call `rim system default ` to set the default R - version then there is no default, and there are no `R` and `RD` + version then there is no default, and there are no `R` and `RS` commands. - If you delete the default R version with `rim rm` or another way, - then the `R` and `RD` commands will kept, but they will point to a + then the `R` and `RS` commands will kept, but they will point to a non-existing directory and fail. "#; @@ -167,7 +167,7 @@ DESCRIPTION installations. This lets you directly run a specific R version. E.g. `R-4.1.2` will start R 4.1.2. - It also adds an `R` and `RD` link that runs the default R version. + It also adds an `R` and `RS` link that runs the default R version. See `rim default`. `rim add` runs `rim system make-links`, so if you only use rim to diff --git a/src/windows.rs b/src/windows.rs index 4b82bdd..3f83c8c 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -351,6 +351,10 @@ pub fn sc_set_default(ver: String) { "@\"C:\\Program Files\\R\\R-" + &ver + "\\bin\\R\" %*\n"; let mut file = File::create(linkfile).unwrap(); file.write_all(cnt.as_bytes()).unwrap(); + + let linkfile2 = base.join("bin").join("RS.bat"); + let mut file2 = File::create(linkfile2).unwrap(); + file2.write_all(cnt.as_bytes()).unwrap(); } pub fn sc_get_default() -> String { From ab71f8263ed102c7f16e1b93da903e9faf1995be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Tue, 25 Jan 2022 11:51:43 +0100 Subject: [PATCH 11/11] Release 0.1.5 --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 8edf529..d4d3a15 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,5 @@ -# rim 0.1.5 (unreleased) +# rim 0.1.5 * Experimental Windows version.