├── .gitignore ├── LICENSE ├── README.md ├── bin ├── R-local-exec └── Renv ├── completions ├── Renv.bash └── Renv.zsh ├── doc ├── README.mdtoc ├── build └── mdtoc.rb └── libexec ├── Renv ├── Renv-commands ├── Renv-completions ├── Renv-exec ├── Renv-global ├── Renv-help ├── Renv-hooks ├── Renv-init ├── Renv-local ├── Renv-prefix ├── Renv-rehash ├── Renv-root ├── Renv-set-default ├── Renv-set-local ├── Renv-sh-shell ├── Renv-shims ├── Renv-version ├── Renv-version-file ├── Renv-version-file-read ├── Renv-version-file-write ├── Renv-version-name ├── Renv-version-origin ├── Renv-versions ├── Renv-whence └── Renv-which /.gitignore: -------------------------------------------------------------------------------- 1 | /plugins 2 | /shims 3 | /version 4 | /versions 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Sam Stephenson, Vanderbilt University 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Simple R Version Management: Renv 2 | 3 | Renv lets you easily switch between multiple versions of R. It's 4 | simple, unobtrusive, and follows the UNIX tradition of single-purpose 5 | tools that do one thing well. 6 | 7 | ### Renv _does…_ 8 | 9 | * Let you **change the global R version** on a per-user basis. 10 | * Provide support for **per-project R versions**. 11 | * Allow you to **override the R version** with an environment 12 | variable. 13 | 14 | ## Table of Contents 15 | 16 | * [1 How It Works](#section_1) 17 | * [2 Installation](#section_2) 18 | * [2.1 Basic GitHub Checkout](#section_2.1) 19 | * [2.1.1 Upgrading](#section_2.1.1) 20 | * [2.2 Neckbeard Configuration](#section_2.2) 21 | * [3 Usage](#section_3) 22 | * [3.1 Renv global](#section_3.1) 23 | * [3.2 Renv local](#section_3.2) 24 | * [3.3 Renv shell](#section_3.3) 25 | * [3.4 Renv versions](#section_3.4) 26 | * [3.5 Renv version](#section_3.5) 27 | * [3.6 Renv rehash](#section_3.6) 28 | * [3.7 Renv which](#section_3.7) 29 | * [3.8 Renv whence](#section_3.8) 30 | * [4 Development](#section_4) 31 | * [4.1 History](#section_4.1) 32 | * [4.2 License](#section_4.2) 33 | 34 | ## 1 How It Works 35 | 36 | Renv operates on the per-user directory `~/.Renv`. Version names in 37 | Renv correspond to subdirectories of `~/.Renv/versions`. For 38 | example, you might have `~/.Renv/versions/2.13.2` and 39 | `~/.Renv/versions/2.14.0`. 40 | 41 | Each version is a working tree with its own binaries, like 42 | `~/.Renv/versions/2.13.2/bin/R` and 43 | `~/.Renv/versions/2.14.0/bin/R`. Renv makes _shim binaries_ 44 | for every such binary across all installed versions of R. 45 | 46 | These shims are simple wrapper scripts that live in `~/.Renv/shims` 47 | and detect which R version you want to use. They insert the 48 | directory for the selected version at the beginning of your `$PATH` 49 | and then execute the corresponding binary. 50 | 51 | Because of the simplicity of the shim approach, all you need to use 52 | Renv is `~/.Renv/shims` in your `$PATH`. 53 | 54 | ## 2 Installation 55 | 56 | ### 2.1 Basic GitHub Checkout 57 | 58 | This will get you going with the latest version of Renv and make it 59 | easy to fork and contribute any changes back upstream. 60 | 61 | 1. Check out Renv into `~/.Renv`. 62 | 63 | $ cd 64 | $ git clone git://github.com/viking/Renv.git .Renv 65 | 66 | 2. Add `~/.Renv/bin` to your `$PATH` for access to the `Renv` 67 | command-line utility. 68 | 69 | $ echo 'export PATH="$HOME/.Renv/bin:$PATH"' >> ~/.bash_profile 70 | 71 | **Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`. 72 | 73 | 3. Add Renv init to your shell to enable shims and autocompletion. 74 | 75 | $ echo 'eval "$(Renv init -)"' >> ~/.bash_profile 76 | 77 | **Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`. 78 | 79 | 4. Restart your shell so the path changes take effect. You can now 80 | begin using Renv. 81 | 82 | $ exec $SHELL 83 | 84 | 5. Install R versions into `~/.Renv/versions`. For example, to 85 | install R 2.14.0, download and unpack the source, then run: 86 | 87 | $ ./configure --prefix=$HOME/.Renv/versions/2.14.0 88 | $ make 89 | $ make install 90 | 91 | You can also use [R-build](https://github.com/viking/R-build) to build and install R versions. 92 | 93 | 6. Rebuild the shim binaries. You should do this any time you install 94 | a new R binary (for example, when installing a new R version). 95 | 96 | $ Renv rehash 97 | 98 | #### 2.1.1 Upgrading 99 | 100 | If you've installed Renv using the instructions above, you can 101 | upgrade your installation at any time using git. 102 | 103 | To upgrade to the latest development version of Renv, use `git pull`: 104 | 105 | $ cd ~/.Renv 106 | $ git pull 107 | 108 | To upgrade to a specific release of Renv, check out the corresponding 109 | tag: 110 | 111 | $ cd ~/.Renv 112 | $ git fetch 113 | $ git tag 114 | v0.1.0 115 | v0.1.1 116 | v0.1.2 117 | v0.2.0 118 | $ git checkout v0.2.0 119 | 120 | ### 2.2 Neckbeard Configuration 121 | 122 | Skip this section unless you must know what every line in your shell 123 | profile is doing. 124 | 125 | `Renv init` is the only command that crosses the line of loading 126 | extra commands into your shell. Coming from rvm, some of you might be 127 | opposed to this idea. Here's what `Renv init` actually does: 128 | 129 | 1. Sets up your shims path. This is the only requirement for Renv to 130 | function properly. You can do this by hand by prepending 131 | `~/.Renv/shims` to your `$PATH`. 132 | 133 | 2. Installs autocompletion. This is entirely optional but pretty 134 | useful. Sourcing `~/.Renv/completions/Renv.bash` will set that 135 | up. There is also a `~/.Renv/completions/Renv.zsh` for Zsh 136 | users. 137 | 138 | 3. Rehashes shims. From time to time you'll need to rebuild your 139 | shim files. Doing this on init makes sure everything is up to 140 | date. You can always run `Renv rehash` manually. 141 | 142 | 4. Installs the sh dispatcher. This bit is also optional, but allows 143 | Renv and plugins to change variables in your current shell, making 144 | commands like `Renv shell` possible. The sh dispatcher doesn't do 145 | anything crazy like override `cd` or hack your shell prompt, but if 146 | for some reason you need `Renv` to be a real script rather than a 147 | shell function, you can safely skip it. 148 | 149 | Run `Renv init -` for yourself to see exactly what happens under the 150 | hood. 151 | 152 | ## 3 Usage 153 | 154 | Like `git`, the `Renv` command delegates to subcommands based on its 155 | first argument. The most common subcommands are: 156 | 157 | ### 3.1 Renv global 158 | 159 | Sets the global version of R to be used in all shells by writing 160 | the version name to the `~/.Renv/version` file. This version can be 161 | overridden by a per-project `.Renv-version` file, or by setting the 162 | `RENV_VERSION` environment variable. 163 | 164 | $ Renv global 2.14.0 165 | 166 | The special version name `system` tells Renv to use the system R 167 | (detected by searching your `$PATH`). 168 | 169 | When run without a version number, `Renv global` reports the 170 | currently configured global version. 171 | 172 | ### 3.2 Renv local 173 | 174 | Sets a local per-project R version by writing the version name to 175 | an `.Renv-version` file in the current directory. This version 176 | overrides the global, and can be overridden itself by setting the 177 | `RENV_VERSION` environment variable or with the `Renv shell` 178 | command. 179 | 180 | $ Renv local 2.11.1 181 | 182 | When run without a version number, `Renv local` reports the currently 183 | configured local version. You can also unset the local version: 184 | 185 | $ Renv local --unset 186 | 187 | ### 3.3 Renv shell 188 | 189 | Sets a shell-specific R version by setting the `RENV_VERSION` 190 | environment variable in your shell. This version overrides both 191 | project-specific versions and the global version. 192 | 193 | $ Renv shell 2.13.2 194 | 195 | When run without a version number, `Renv shell` reports the current 196 | value of `RENV_VERSION`. You can also unset the shell version: 197 | 198 | $ Renv shell --unset 199 | 200 | Note that you'll need Renv's shell integration enabled (step 3 of 201 | the installation instructions) in order to use this command. If you 202 | prefer not to use shell integration, you may simply set the 203 | `RENV_VERSION` variable yourself: 204 | 205 | $ export RENV_VERSION=2.13.2 206 | 207 | ### 3.4 Renv versions 208 | 209 | Lists all R versions known to Renv, and shows an asterisk next to 210 | the currently active version. 211 | 212 | $ Renv versions 213 | 2.10.1 214 | 2.11.1 215 | * 2.14.0 (set by /Users/sam/.Renv/global) 216 | 217 | ### 3.5 Renv version 218 | 219 | Displays the currently active R version, along with information on 220 | how it was set. 221 | 222 | $ Renv version 223 | 2.14.0 (set by /home/viking/Projects/yaml/.Renv-version) 224 | 225 | ### 3.6 Renv rehash 226 | 227 | Installs shims for all R binaries known to Renv (i.e., 228 | `~/.Renv/versions/*/bin/*`). Run this command after you install a new 229 | version of R. 230 | 231 | $ Renv rehash 232 | 233 | ### 3.7 Renv which 234 | 235 | Displays the full path to the binary that Renv will execute when you 236 | run the given command. 237 | 238 | $ Renv which irb 239 | /home/viking/.Renv/versions/2.14.0/bin/R 240 | 241 | ### 3.8 Renv whence 242 | 243 | Lists all R versions with the given command installed. 244 | 245 | $ Renv whence R 246 | 2.13.2 247 | 2.14.0 248 | 249 | ## 4 Development 250 | 251 | The Renv source code is [hosted on 252 | GitHub](https://github.com/viking/Renv). It's clean, modular, 253 | and easy to understand, even if you're not a shell hacker. 254 | 255 | Please feel free to submit pull requests and file bugs on the [issue 256 | tracker](https://github.com/viking/Renv/issues). 257 | 258 | ### 4.1 Version History 259 | 260 | Renv is a forked version of [rbenv](https://github.com/sstephenson/rbenv). 261 | 262 | ### 4.2 License 263 | 264 | (The MIT license) 265 | 266 | Copyright (c) 2011 Sam Stephenson, Vanderbilt University 267 | 268 | Permission is hereby granted, free of charge, to any person obtaining 269 | a copy of this software and associated documentation files (the 270 | "Software"), to deal in the Software without restriction, including 271 | without limitation the rights to use, copy, modify, merge, publish, 272 | distribute, sublicense, and/or sell copies of the Software, and to 273 | permit persons to whom the Software is furnished to do so, subject to 274 | the following conditions: 275 | 276 | The above copyright notice and this permission notice shall be 277 | included in all copies or substantial portions of the Software. 278 | 279 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 280 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 281 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 282 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 283 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 284 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 285 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 286 | -------------------------------------------------------------------------------- /bin/R-local-exec: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # `R-local-exec` is a drop-in replacement for the standard R 4 | # shebang line: 5 | # 6 | # #!/usr/bin/env R-local-exec 7 | # 8 | # Use it for scripts inside a project with an `.Renv-version` 9 | # file. When you run the scripts, they'll use the project-specified 10 | # R version, regardless of what directory they're run from. Useful 11 | # for e.g. running project tasks in cron scripts without needing to 12 | # `cd` into the project first. 13 | 14 | set -e 15 | export RENV_DIR="${1%/*}" 16 | exec R "$@" 17 | -------------------------------------------------------------------------------- /bin/Renv: -------------------------------------------------------------------------------- 1 | ../libexec/Renv -------------------------------------------------------------------------------- /completions/Renv.bash: -------------------------------------------------------------------------------- 1 | _Renv() { 2 | COMPREPLY=() 3 | local word="${COMP_WORDS[COMP_CWORD]}" 4 | 5 | if [ "$COMP_CWORD" -eq 1 ]; then 6 | COMPREPLY=( $(compgen -W "$(Renv commands)" -- "$word") ) 7 | else 8 | local command="${COMP_WORDS[1]}" 9 | local completions="$(Renv completions "$command")" 10 | COMPREPLY=( $(compgen -W "$completions" -- "$word") ) 11 | fi 12 | } 13 | 14 | complete -F _Renv Renv 15 | -------------------------------------------------------------------------------- /completions/Renv.zsh: -------------------------------------------------------------------------------- 1 | if [[ ! -o interactive ]]; then 2 | return 3 | fi 4 | 5 | compctl -K _Renv Renv 6 | 7 | _Renv() { 8 | local word words completions 9 | read -cA words 10 | word="${words[2]}" 11 | 12 | if [ "${#words}" -eq 2 ]; then 13 | completions="$(Renv commands)" 14 | else 15 | completions="$(Renv completions "${word}")" 16 | fi 17 | 18 | reply=("${(ps:\n:)completions}") 19 | } 20 | -------------------------------------------------------------------------------- /doc/README.mdtoc: -------------------------------------------------------------------------------- 1 | # Simple R Version Management: Renv 2 | 3 | Renv lets you easily switch between multiple versions of R. It's 4 | simple, unobtrusive, and follows the UNIX tradition of single-purpose 5 | tools that do one thing well. 6 | 7 | ### Renv _does…_ 8 | 9 | * Let you **change the global R version** on a per-user basis. 10 | * Provide support for **per-project R versions**. 11 | * Allow you to **override the R version** with an environment 12 | variable. 13 | 14 | ## Table of Contents 15 | 16 | * [1 How It Works](#section_1) 17 | * [2 Installation](#section_2) 18 | * [2.1 Basic GitHub Checkout](#section_2.1) 19 | * [2.1.1 Upgrading](#section_2.1.1) 20 | * [2.2 Neckbeard Configuration](#section_2.2) 21 | * [3 Usage](#section_3) 22 | * [3.1 Renv global](#section_3.1) 23 | * [3.2 Renv local](#section_3.2) 24 | * [3.3 Renv shell](#section_3.3) 25 | * [3.4 Renv versions](#section_3.4) 26 | * [3.5 Renv version](#section_3.5) 27 | * [3.6 Renv rehash](#section_3.6) 28 | * [3.7 Renv which](#section_3.7) 29 | * [3.8 Renv whence](#section_3.8) 30 | * [4 Development](#section_4) 31 | * [4.1 History](#section_4.1) 32 | * [4.2 License](#section_4.2) 33 | 34 | ## 1 How It Works 35 | 36 | Renv operates on the per-user directory `~/.Renv`. Version names in 37 | Renv correspond to subdirectories of `~/.Renv/versions`. For 38 | example, you might have `~/.Renv/versions/2.13.2` and 39 | `~/.Renv/versions/2.14.0`. 40 | 41 | Each version is a working tree with its own binaries, like 42 | `~/.Renv/versions/2.13.2/bin/R` and 43 | `~/.Renv/versions/2.14.0/bin/R`. Renv makes _shim binaries_ 44 | for every such binary across all installed versions of R. 45 | 46 | These shims are simple wrapper scripts that live in `~/.Renv/shims` 47 | and detect which R version you want to use. They insert the 48 | directory for the selected version at the beginning of your `$PATH` 49 | and then execute the corresponding binary. 50 | 51 | Because of the simplicity of the shim approach, all you need to use 52 | Renv is `~/.Renv/shims` in your `$PATH`. 53 | 54 | ## 2 Installation 55 | 56 | ### 2.1 Basic GitHub Checkout 57 | 58 | This will get you going with the latest version of Renv and make it 59 | easy to fork and contribute any changes back upstream. 60 | 61 | 1. Check out Renv into `~/.Renv`. 62 | 63 | $ cd 64 | $ git clone git://github.com/viking/Renv.git .Renv 65 | 66 | 2. Add `~/.Renv/bin` to your `$PATH` for access to the `Renv` 67 | command-line utility. 68 | 69 | $ echo 'export PATH="$HOME/.Renv/bin:$PATH"' >> ~/.bash_profile 70 | 71 | **Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`. 72 | 73 | 3. Add Renv init to your shell to enable shims and autocompletion. 74 | 75 | $ echo 'eval "$(Renv init -)"' >> ~/.bash_profile 76 | 77 | **Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`. 78 | 79 | 4. Restart your shell so the path changes take effect. You can now 80 | begin using Renv. 81 | 82 | $ exec $SHELL 83 | 84 | 5. Install R versions into `~/.Renv/versions`. For example, to 85 | install R 2.14.0, download and unpack the source, then run: 86 | 87 | $ ./configure --prefix=$HOME/.Renv/versions/2.14.0 88 | $ make 89 | $ make install 90 | 91 | You can also use [R-build](https://github.com/viking/R-build) to build and install R versions. 92 | 93 | 6. Rebuild the shim binaries. You should do this any time you install 94 | a new R binary (for example, when installing a new R version). 95 | 96 | $ Renv rehash 97 | 98 | #### 2.1.1 Upgrading 99 | 100 | If you've installed Renv using the instructions above, you can 101 | upgrade your installation at any time using git. 102 | 103 | To upgrade to the latest development version of Renv, use `git pull`: 104 | 105 | $ cd ~/.Renv 106 | $ git pull 107 | 108 | To upgrade to a specific release of Renv, check out the corresponding 109 | tag: 110 | 111 | $ cd ~/.Renv 112 | $ git fetch 113 | $ git tag 114 | v0.1.0 115 | v0.1.1 116 | v0.1.2 117 | v0.2.0 118 | $ git checkout v0.2.0 119 | 120 | ### 2.2 Neckbeard Configuration 121 | 122 | Skip this section unless you must know what every line in your shell 123 | profile is doing. 124 | 125 | `Renv init` is the only command that crosses the line of loading 126 | extra commands into your shell. Coming from rvm, some of you might be 127 | opposed to this idea. Here's what `Renv init` actually does: 128 | 129 | 1. Sets up your shims path. This is the only requirement for Renv to 130 | function properly. You can do this by hand by prepending 131 | `~/.Renv/shims` to your `$PATH`. 132 | 133 | 2. Installs autocompletion. This is entirely optional but pretty 134 | useful. Sourcing `~/.Renv/completions/Renv.bash` will set that 135 | up. There is also a `~/.Renv/completions/Renv.zsh` for Zsh 136 | users. 137 | 138 | 3. Rehashes shims. From time to time you'll need to rebuild your 139 | shim files. Doing this on init makes sure everything is up to 140 | date. You can always run `Renv rehash` manually. 141 | 142 | 4. Installs the sh dispatcher. This bit is also optional, but allows 143 | Renv and plugins to change variables in your current shell, making 144 | commands like `Renv shell` possible. The sh dispatcher doesn't do 145 | anything crazy like override `cd` or hack your shell prompt, but if 146 | for some reason you need `Renv` to be a real script rather than a 147 | shell function, you can safely skip it. 148 | 149 | Run `Renv init -` for yourself to see exactly what happens under the 150 | hood. 151 | 152 | ## 3 Usage 153 | 154 | Like `git`, the `Renv` command delegates to subcommands based on its 155 | first argument. The most common subcommands are: 156 | 157 | ### 3.1 Renv global 158 | 159 | Sets the global version of R to be used in all shells by writing 160 | the version name to the `~/.Renv/version` file. This version can be 161 | overridden by a per-project `.Renv-version` file, or by setting the 162 | `RENV_VERSION` environment variable. 163 | 164 | $ Renv global 2.14.0 165 | 166 | The special version name `system` tells Renv to use the system R 167 | (detected by searching your `$PATH`). 168 | 169 | When run without a version number, `Renv global` reports the 170 | currently configured global version. 171 | 172 | ### 3.2 Renv local 173 | 174 | Sets a local per-project R version by writing the version name to 175 | an `.Renv-version` file in the current directory. This version 176 | overrides the global, and can be overridden itself by setting the 177 | `RENV_VERSION` environment variable or with the `Renv shell` 178 | command. 179 | 180 | $ Renv local 2.11.1 181 | 182 | When run without a version number, `Renv local` reports the currently 183 | configured local version. You can also unset the local version: 184 | 185 | $ Renv local --unset 186 | 187 | ### 3.3 Renv shell 188 | 189 | Sets a shell-specific R version by setting the `RENV_VERSION` 190 | environment variable in your shell. This version overrides both 191 | project-specific versions and the global version. 192 | 193 | $ Renv shell 2.13.2 194 | 195 | When run without a version number, `Renv shell` reports the current 196 | value of `RENV_VERSION`. You can also unset the shell version: 197 | 198 | $ Renv shell --unset 199 | 200 | Note that you'll need Renv's shell integration enabled (step 3 of 201 | the installation instructions) in order to use this command. If you 202 | prefer not to use shell integration, you may simply set the 203 | `RENV_VERSION` variable yourself: 204 | 205 | $ export RENV_VERSION=2.13.2 206 | 207 | ### 3.4 Renv versions 208 | 209 | Lists all R versions known to Renv, and shows an asterisk next to 210 | the currently active version. 211 | 212 | $ Renv versions 213 | 2.10.1 214 | 2.11.1 215 | * 2.14.0 (set by /Users/sam/.Renv/global) 216 | 217 | ### 3.5 Renv version 218 | 219 | Displays the currently active R version, along with information on 220 | how it was set. 221 | 222 | $ Renv version 223 | 2.14.0 (set by /home/viking/Projects/yaml/.Renv-version) 224 | 225 | ### 3.6 Renv rehash 226 | 227 | Installs shims for all R binaries known to Renv (i.e., 228 | `~/.Renv/versions/*/bin/*`). Run this command after you install a new 229 | version of R. 230 | 231 | $ Renv rehash 232 | 233 | ### 3.7 Renv which 234 | 235 | Displays the full path to the binary that Renv will execute when you 236 | run the given command. 237 | 238 | $ Renv which irb 239 | /home/viking/.Renv/versions/2.14.0/bin/R 240 | 241 | ### 3.8 Renv whence 242 | 243 | Lists all R versions with the given command installed. 244 | 245 | $ Renv whence R 246 | 2.13.2 247 | 2.14.0 248 | 249 | ## 4 Development 250 | 251 | The Renv source code is [hosted on 252 | GitHub](https://github.com/viking/Renv). It's clean, modular, 253 | and easy to understand, even if you're not a shell hacker. 254 | 255 | Please feel free to submit pull requests and file bugs on the [issue 256 | tracker](https://github.com/viking/Renv/issues). 257 | 258 | ### 4.1 Version History 259 | 260 | Renv is a forked version of [rbenv](https://github.com/sstephenson/rbenv). 261 | 262 | ### 4.2 License 263 | 264 | (The MIT license) 265 | 266 | Copyright (c) 2011 Sam Stephenson, Vanderbilt University 267 | 268 | Permission is hereby granted, free of charge, to any person obtaining 269 | a copy of this software and associated documentation files (the 270 | "Software"), to deal in the Software without restriction, including 271 | without limitation the rights to use, copy, modify, merge, publish, 272 | distribute, sublicense, and/or sell copies of the Software, and to 273 | permit persons to whom the Software is furnished to do so, subject to 274 | the following conditions: 275 | 276 | The above copyright notice and this permission notice shall be 277 | included in all copies or substantial portions of the Software. 278 | 279 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 280 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 281 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 282 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 283 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 284 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 285 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 286 | -------------------------------------------------------------------------------- /doc/build: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | 3 | ruby mdtoc.rb README.mdtoc > ../README.md 4 | 5 | -------------------------------------------------------------------------------- /doc/mdtoc.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # A little Markdown filter that scans your document for headings, 4 | # numbers them, adds anchors, and inserts a table of contents. 5 | # 6 | # To use it, make sure the headings you want numbered and linked are 7 | # in this format: 8 | # 9 | # ### Title ### 10 | # 11 | # I.e. they must have an equal number of octothorpes around the title 12 | # text. (In Markdown, `#` means `h1`, `##` means `h2`, and so on.) 13 | # The table of contents will be inserted before the first such 14 | # heading. 15 | # 16 | # Released into the public domain. 17 | # Sam Stephenson 18 | # 2011-04-30 19 | 20 | def mdtoc(markdown) 21 | titles = [] 22 | lines = markdown.split($/) 23 | start = nil 24 | 25 | # First pass: Scan the Markdown source looking for titles of the 26 | # format: `### Title ###`. Record the line number, header level 27 | # (number of octothorpes), and text of each matching title. 28 | lines.each_with_index do |line, line_no| 29 | if line.match(/^(\#{1,6})\s+(.+?)\s+\1$/) 30 | titles << [line_no, $1.length, $2] 31 | start ||= line_no 32 | end 33 | end 34 | 35 | last_section = nil 36 | last_level = nil 37 | 38 | # Second pass: Iterate over all matched titles and compute their 39 | # corresponding section numbers. Then replace the titles with 40 | # annotated anchors. 41 | titles.each do |title_info| 42 | line_no, level, text = title_info 43 | 44 | if last_section 45 | section = last_section.dup 46 | 47 | if last_level < level 48 | section << 1 49 | else 50 | (last_level - level).times { section.pop } 51 | section[-1] += 1 52 | end 53 | else 54 | section = [1] 55 | end 56 | 57 | name = section.join(".") 58 | lines[line_no] = %(#{"#" * level} #{name} #{text}) 59 | 60 | title_info << section 61 | last_section = section 62 | last_level = level 63 | end 64 | 65 | # Third pass: Iterate over matched titles once more to produce the 66 | # table of contents. Then insert it immediately above the first 67 | # matched title. 68 | if start 69 | toc = titles.map do |(line_no, level, text, section)| 70 | name = section.join(".") 71 | %(#{" " * (section.length * 3)}* [#{name} #{text}](#section_#{name})) 72 | end + [""] 73 | 74 | lines.insert(start, *toc) 75 | end 76 | 77 | lines.join("\n") 78 | end 79 | 80 | if __FILE__ == $0 81 | puts mdtoc($<.read) 82 | end 83 | -------------------------------------------------------------------------------- /libexec/Renv: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | [ -n "$RENV_DEBUG" ] && set -x 4 | 5 | resolve_link() { 6 | $(type -p greadlink readlink | head -1) "$1" 7 | } 8 | 9 | abs_dirname() { 10 | local cwd="$(pwd)" 11 | local path="$1" 12 | 13 | while [ -n "$path" ]; do 14 | cd "${path%/*}" 15 | local name="${path##*/}" 16 | path="$(resolve_link "$name" || true)" 17 | done 18 | 19 | pwd 20 | cd "$cwd" 21 | } 22 | 23 | if [ -z "${RENV_ROOT}" ]; then 24 | RENV_ROOT="${HOME}/.Renv" 25 | else 26 | RENV_ROOT="${RENV_ROOT%/}" 27 | fi 28 | export RENV_ROOT 29 | 30 | if [ -z "${RENV_DIR}" ]; then 31 | RENV_DIR="$(pwd)" 32 | else 33 | cd "$RENV_DIR" 2>/dev/null || { 34 | echo "Renv: cannot change working directory to \`$RENV_DIR'" 35 | exit 1 36 | } >&2 37 | RENV_DIR="$(pwd)" 38 | cd "$OLDPWD" 39 | fi 40 | export RENV_DIR 41 | 42 | 43 | shopt -s nullglob 44 | 45 | bin_path="$(abs_dirname "$0")" 46 | for plugin_bin in "${RENV_ROOT}/plugins/"*/bin; do 47 | bin_path="${bin_path}:${plugin_bin}" 48 | done 49 | export PATH="${bin_path}:${PATH}" 50 | 51 | hook_path="${RENV_HOOK_PATH}:${RENV_ROOT}/Renv.d:/usr/local/etc/Renv.d:/etc/Renv.d:/usr/lib/Renv/hooks" 52 | for plugin_hook in "${RENV_ROOT}/plugins/"*/etc/Renv.d; do 53 | hook_path="${hook_path}:${plugin_hook}" 54 | done 55 | export RENV_HOOK_PATH="$hook_path" 56 | 57 | shopt -u nullglob 58 | 59 | 60 | command="$1" 61 | case "$command" in 62 | "" | "-h" | "--help" ) 63 | echo -e "Renv 0.3.0\n$(Renv-help)" >&2 64 | ;; 65 | * ) 66 | command_path="$(command -v "Renv-$command" || true)" 67 | if [ -z "$command_path" ]; then 68 | echo "Renv: no such command \`$command'" >&2 69 | exit 1 70 | fi 71 | 72 | shift 1 73 | exec "$command_path" "$@" 74 | ;; 75 | esac 76 | -------------------------------------------------------------------------------- /libexec/Renv-commands: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | [ -n "$RENV_DEBUG" ] && set -x 4 | 5 | # Provide Renv completions 6 | if [ "$1" = "--complete" ]; then 7 | echo --sh 8 | echo --no-sh 9 | exit 10 | fi 11 | 12 | if [ "$1" = "--sh" ]; then 13 | sh=1 14 | shift 15 | elif [ "$1" = "--no-sh" ]; then 16 | nosh=1 17 | shift 18 | fi 19 | 20 | shopt -s nullglob 21 | 22 | { for path in ${PATH//:/$'\n'}; do 23 | for command in "${path}/Renv-"*; do 24 | command="${command##*Renv-}" 25 | if [ -n "$sh" ]; then 26 | if [ ${command:0:3} = "sh-" ]; then 27 | echo ${command##sh-} 28 | fi 29 | elif [ -n "$nosh" ]; then 30 | if [ ${command:0:3} != "sh-" ]; then 31 | echo ${command##sh-} 32 | fi 33 | else 34 | echo ${command##sh-} 35 | fi 36 | done 37 | done 38 | } | sort | uniq 39 | -------------------------------------------------------------------------------- /libexec/Renv-completions: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | [ -n "$RENV_DEBUG" ] && set -x 4 | 5 | COMMAND="$1" 6 | if [ -z "$COMMAND" ]; then 7 | echo "usage: Renv completions COMMAND [arg1 arg2...]" >&2 8 | exit 1 9 | fi 10 | 11 | COMMAND_PATH="$(command -v "Renv-$COMMAND" || command -v "Renv-sh-$COMMAND")" 12 | if grep -i "^# provide Renv completions" "$COMMAND_PATH" >/dev/null; then 13 | shift 14 | exec "$COMMAND_PATH" --complete "$@" 15 | fi 16 | -------------------------------------------------------------------------------- /libexec/Renv-exec: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | [ -n "$RENV_DEBUG" ] && set -x 4 | 5 | # Provide Renv completions 6 | if [ "$1" = "--complete" ]; then 7 | exec Renv shims --short 8 | fi 9 | 10 | RENV_COMMAND="$1" 11 | if [ -z "$RENV_COMMAND" ]; then 12 | echo "usage: Renv exec COMMAND [arg1 arg2...]" >&2 13 | exit 1 14 | fi 15 | 16 | RENV_COMMAND_PATH="$(Renv-which "$RENV_COMMAND")" 17 | RENV_BIN_PATH="${RENV_COMMAND_PATH%/*}" 18 | 19 | for script in $(Renv-hooks exec); do 20 | source "$script" 21 | done 22 | 23 | shift 1 24 | export PATH="${RENV_BIN_PATH}:${PATH}" 25 | exec -a "$RENV_COMMAND" "$RENV_COMMAND_PATH" "$@" 26 | -------------------------------------------------------------------------------- /libexec/Renv-global: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | [ -n "$RENV_DEBUG" ] && set -x 4 | 5 | # Provide Renv completions 6 | if [ "$1" = "--complete" ]; then 7 | echo system 8 | exec Renv-versions --bare 9 | fi 10 | 11 | RENV_VERSION="$1" 12 | RENV_VERSION_FILE="${RENV_ROOT}/version" 13 | 14 | if [ -n "$RENV_VERSION" ]; then 15 | Renv-version-file-write "$RENV_VERSION_FILE" "$RENV_VERSION" 16 | else 17 | Renv-version-file-read "$RENV_VERSION_FILE" || 18 | Renv-version-file-read "${RENV_ROOT}/global" || 19 | Renv-version-file-read "${RENV_ROOT}/default" || 20 | echo system 21 | fi 22 | -------------------------------------------------------------------------------- /libexec/Renv-help: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | [ -n "$RENV_DEBUG" ] && set -x 4 | 5 | print_set_version() { 6 | echo " should be a string matching a R version known by Renv." 7 | 8 | local versions="$(Renv-versions --bare)" 9 | if [ -z "$versions" ]; then 10 | echo "There are currently no R versions installed for Renv." 11 | else 12 | echo "The currently installed R versions are:" 13 | echo "$versions" | sed 's/^/ /' 14 | fi 15 | 16 | echo 17 | echo "The special version string 'system' will use your default system R." 18 | } 19 | 20 | case "$1" in 21 | "") echo "usage: Renv [] 22 | 23 | Some useful Renv commands are: 24 | commands List all Renv commands 25 | rehash Rehash Renv shims (run this after installing binaries) 26 | global Set or show the global R version 27 | local Set or show the local directory-specific R version 28 | shell Set or show the shell-specific R version 29 | version Show the current R version 30 | versions List all R versions known by Renv 31 | which Show the full path for the given R command 32 | whence List all R versions with the given command 33 | 34 | See 'Renv help ' for information on a specific command. 35 | For full documentation, see: https://github.com/viking/Renv#readme" 36 | ;; 37 | commands) echo "usage: Renv commands 38 | Renv commands --sh 39 | Renv commands --no-sh 40 | 41 | List all Renv commands." 42 | ;; 43 | global) echo "usage: Renv global 44 | 45 | Sets the global R version. You can override the global version at 46 | any time by setting a directory-specific version with \`Renv local' 47 | or by setting the RENV_VERSION environment variable. 48 | 49 | $(print_set_version)" 50 | ;; 51 | local) echo "usage: Renv local 52 | Renv local --unset 53 | 54 | Sets the local directory-specific R version by writing the version 55 | name to a file named '.Renv-version'. 56 | 57 | When you run a R command, Renv will look for an '.Renv-version' 58 | file in the current directory and each parent directory. If no such 59 | file is found in the tree, Renv will use the global R version 60 | specified with \`Renv global', or the version specified in the 61 | RENV_VERSION environment variable. 62 | 63 | $(print_set_version)" 64 | ;; 65 | shell) echo "usage: Renv shell 66 | Renv shell --unset 67 | 68 | Sets a shell-specific R version by setting the 'RENV_VERSION' 69 | environment variable in your shell. This version overrides both 70 | project-specific versions and the global version. 71 | 72 | $(print_set_version)" 73 | ;; 74 | versions) echo "usage: Renv versions 75 | Renv versions --bare 76 | 77 | Lists all R versions known by Renv." 78 | ;; 79 | which) echo "usage: Renv which 80 | 81 | Displays the full path to the binary that Renv will execute when you 82 | run the given command." 83 | ;; 84 | whence) echo "usage: Renv whence 85 | 86 | Lists all R versions with the given command installed." 87 | ;; 88 | *) 89 | command_path="$(command -v "Renv-$1" || true)" 90 | if [ -n "$command_path" ]; then 91 | echo "Sorry, the \`$1' command isn't documented yet." 92 | echo 93 | echo "You can view the command's source here:" 94 | echo "$command_path" 95 | echo 96 | else 97 | echo "Renv: no such command \`$1'" 98 | fi 99 | esac 100 | -------------------------------------------------------------------------------- /libexec/Renv-hooks: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | [ -n "$RENV_DEBUG" ] && set -x 4 | 5 | # Provide Renv completions 6 | if [ "$1" = "--complete" ]; then 7 | echo exec 8 | echo rehash 9 | echo which 10 | exit 11 | fi 12 | 13 | RENV_COMMAND="$1" 14 | if [ -z "$RENV_COMMAND" ]; then 15 | echo "usage: Renv hooks COMMAND" >&2 16 | exit 1 17 | fi 18 | 19 | resolve_link() { 20 | $(type -p greadlink readlink | head -1) $1 21 | } 22 | 23 | realpath() { 24 | local cwd="$(pwd)" 25 | local base="$(basename $1)" 26 | local path="$1" 27 | 28 | while [ -n "$path" ]; do 29 | cd "${path%/*}" 30 | local name="${path##*/}" 31 | path="$(resolve_link "$name" || true)" 32 | done 33 | 34 | echo "$(pwd)/$base" 35 | cd "$cwd" 36 | } 37 | 38 | shopt -s nullglob 39 | for path in ${RENV_HOOK_PATH//:/$'\n'}; do 40 | for script in $path/"$RENV_COMMAND"/*.bash; do 41 | echo $(realpath $script) 42 | done 43 | done 44 | shopt -u nullglob 45 | -------------------------------------------------------------------------------- /libexec/Renv-init: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | [ -n "$RENV_DEBUG" ] && set -x 4 | 5 | print="" 6 | no_rehash="" 7 | for args in "$@" 8 | do 9 | if [ "$args" = "-" ]; then 10 | print=1 11 | shift 12 | fi 13 | 14 | if [ "$args" = "--no-rehash" ]; then 15 | no_rehash=1 16 | shift 17 | fi 18 | done 19 | 20 | shell="$1" 21 | if [ -z "$shell" ]; then 22 | shell="$(basename "$SHELL")" 23 | fi 24 | 25 | resolve_link() { 26 | $(type -p greadlink readlink | head -1) $1 27 | } 28 | 29 | abs_dirname() { 30 | local cwd="$(pwd)" 31 | local path="$1" 32 | 33 | while [ -n "$path" ]; do 34 | cd "${path%/*}" 35 | local name="${path##*/}" 36 | path="$(resolve_link "$name" || true)" 37 | done 38 | 39 | pwd 40 | cd "$cwd" 41 | } 42 | 43 | root="$(abs_dirname "$0")/.." 44 | 45 | if [ -z "$print" ]; then 46 | case "$shell" in 47 | bash ) 48 | profile='~/.bash_profile' 49 | ;; 50 | zsh ) 51 | profile='~/.zshrc' 52 | ;; 53 | ksh ) 54 | profile='~/.profile' 55 | ;; 56 | * ) 57 | profile='your profile' 58 | ;; 59 | esac 60 | 61 | { echo "# Load Renv automatically by adding" 62 | echo "# the following to ${profile}:" 63 | echo 64 | echo 'eval "$(Renv init -)"' 65 | echo 66 | } >&2 67 | 68 | exit 1 69 | fi 70 | 71 | mkdir -p "${RENV_ROOT}/"{shims,versions} 72 | 73 | echo 'export PATH="'${RENV_ROOT}'/shims:${PATH}"' 74 | 75 | case "$shell" in 76 | bash | zsh ) 77 | echo "source \"$root/completions/Renv.${shell}\"" 78 | ;; 79 | esac 80 | 81 | if [ -z "$no_rehash" ]; then 82 | echo 'Renv rehash 2>/dev/null' 83 | fi 84 | 85 | commands=(`Renv commands --sh`) 86 | IFS="|" 87 | cat <&2 24 | fi 25 | -------------------------------------------------------------------------------- /libexec/Renv-prefix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | [ -n "$RENV_DEBUG" ] && set -x 4 | 5 | # Provide Renv completions 6 | if [ "$1" = "--complete" ]; then 7 | echo system 8 | exec Renv-versions --bare 9 | fi 10 | 11 | if [ -n "$1" ]; then 12 | export RENV_VERSION="$1" 13 | elif [ -z "$RENV_VERSION" ]; then 14 | RENV_VERSION="$(Renv-version-name)" 15 | fi 16 | 17 | if [ "$RENV_VERSION" = "system" ]; then 18 | R_PATH="$(Renv-which R)" 19 | echo "${R_PATH%/*}" 20 | exit 21 | fi 22 | 23 | RENV_PREFIX_PATH="${RENV_ROOT}/versions/${RENV_VERSION}" 24 | if [ ! -d "$RENV_PREFIX_PATH" ]; then 25 | echo "Renv: version \`${RENV_VERSION}' not installed" >&2 26 | exit 1 27 | fi 28 | 29 | echo "$RENV_PREFIX_PATH" 30 | -------------------------------------------------------------------------------- /libexec/Renv-rehash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | [ -n "$RENV_DEBUG" ] && set -x 4 | 5 | SHIM_PATH="${RENV_ROOT}/shims" 6 | PROTOTYPE_SHIM_PATH="${SHIM_PATH}/.Renv-shim" 7 | 8 | # Create the shims directory if it doesn't already exist. 9 | mkdir -p "$SHIM_PATH" 10 | 11 | # Ensure only one instance of Renv-rehash is running at a time by 12 | # setting the shell's `noclobber` option and attempting to write to 13 | # the prototype shim file. If the file already exists, print a warning 14 | # to stderr and exit with a non-zero status. 15 | set -o noclobber 16 | { echo > "$PROTOTYPE_SHIM_PATH" 17 | } 2>/dev/null || 18 | { echo "Renv: cannot rehash: $PROTOTYPE_SHIM_PATH exists" 19 | exit 1 20 | } >&2 21 | set +o noclobber 22 | 23 | # If we were able to obtain a lock, register a trap to clean up the 24 | # prototype shim when the process exits. 25 | trap remove_prototype_shim EXIT 26 | 27 | remove_prototype_shim() { 28 | rm -f "$PROTOTYPE_SHIM_PATH" 29 | } 30 | 31 | # The prototype shim file is a script that re-execs itself, passing 32 | # its filename and any arguments to `Renv exec`. This file is 33 | # hard-linked for every binary and then removed. The linking technique 34 | # is fast, uses less disk space than unique files, and also serves as 35 | # a locking mechanism. 36 | create_prototype_shim() { 37 | cat > "$PROTOTYPE_SHIM_PATH" <&2 8 | 9 | exec Renv-global "$@" 10 | -------------------------------------------------------------------------------- /libexec/Renv-set-local: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | { echo "Renv: warning: \`set-local' has been renamed to \`local'" 5 | echo " and will be removed in v0.3.0" 6 | echo 7 | } >&2 8 | 9 | exec Renv-local "$@" 10 | -------------------------------------------------------------------------------- /libexec/Renv-sh-shell: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | [ -n "$RENV_DEBUG" ] && set -x 4 | 5 | # Provide Renv completions 6 | if [ "$1" = "--complete" ]; then 7 | echo --unset 8 | echo system 9 | exec Renv-versions --bare 10 | fi 11 | 12 | version="$1" 13 | 14 | if [ -z "$version" ]; then 15 | if [ -z "$RENV_VERSION" ]; then 16 | echo "Renv: no shell-specific version configured" >&2 17 | exit 1 18 | else 19 | echo "echo \"\$RENV_VERSION\"" 20 | exit 21 | fi 22 | fi 23 | 24 | if [ "$version" = "--unset" ]; then 25 | echo "unset RENV_VERSION" 26 | exit 1 27 | fi 28 | 29 | # Make sure the specified version is installed. 30 | Renv-prefix "$version" >/dev/null 31 | 32 | echo "export RENV_VERSION=\"${version}\"" 33 | -------------------------------------------------------------------------------- /libexec/Renv-shims: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | [ -n "$RENV_DEBUG" ] && set -x 4 | 5 | # Provide Renv completions 6 | if [ "$1" = "--complete" ]; then 7 | echo --short 8 | exit 9 | fi 10 | 11 | for command in "${RENV_ROOT}/shims/"*; do 12 | if [ "$1" = "--short" ]; then 13 | echo "${command##*/}" 14 | else 15 | echo "$command" 16 | fi 17 | done | sort 18 | -------------------------------------------------------------------------------- /libexec/Renv-version: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | [ -n "$RENV_DEBUG" ] && set -x 4 | 5 | echo "$(Renv-version-name) (set by $(Renv-version-origin))" 6 | -------------------------------------------------------------------------------- /libexec/Renv-version-file: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | [ -n "$RENV_DEBUG" ] && set -x 4 | 5 | root="$RENV_DIR" 6 | while [ -n "$root" ]; do 7 | if [ -e "${root}/.Renv-version" ]; then 8 | echo "${root}/.Renv-version" 9 | exit 10 | fi 11 | root="${root%/*}" 12 | done 13 | 14 | global_version_file="${RENV_ROOT}/version" 15 | 16 | if [ -e "$global_version_file" ]; then 17 | echo "$global_version_file" 18 | elif [ -e "${RENV_ROOT}/global" ]; then 19 | echo "${RENV_ROOT}/global" 20 | elif [ -e "${RENV_ROOT}/default" ]; then 21 | echo "${RENV_ROOT}/default" 22 | else 23 | echo "$global_version_file" 24 | fi 25 | -------------------------------------------------------------------------------- /libexec/Renv-version-file-read: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | [ -n "$RENV_DEBUG" ] && set -x 4 | 5 | VERSION_FILE="$1" 6 | 7 | if [ -e "$VERSION_FILE" ]; then 8 | # Read and print the first non-whitespace word from the specified 9 | # version file. 10 | version="" 11 | while read -a words; do 12 | word="${words[0]}" 13 | if [ -z "$version" ] && [ -n "$word" ]; then 14 | version="$word" 15 | fi 16 | done < <( cat "$VERSION_FILE" && echo ) 17 | 18 | if [ -n "$version" ]; then 19 | echo "$version" 20 | exit 21 | fi 22 | fi 23 | 24 | exit 1 25 | -------------------------------------------------------------------------------- /libexec/Renv-version-file-write: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | [ -n "$RENV_DEBUG" ] && set -x 4 | 5 | RENV_VERSION_FILE="$1" 6 | RENV_VERSION="$2" 7 | 8 | if [ -z "$RENV_VERSION" ] || [ -z "$RENV_VERSION_FILE" ]; then 9 | echo "usage: Renv write-version-file FILENAME VERSION" >&2 10 | exit 1 11 | fi 12 | 13 | # Make sure the specified version is installed. 14 | Renv-prefix "$RENV_VERSION" >/dev/null 15 | 16 | # Write the version out to disk. 17 | echo "$RENV_VERSION" > "$RENV_VERSION_FILE" 18 | -------------------------------------------------------------------------------- /libexec/Renv-version-name: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | [ -n "$RENV_DEBUG" ] && set -x 4 | 5 | if [ -z "$RENV_VERSION" ]; then 6 | RENV_VERSION_FILE="$(Renv-version-file)" 7 | RENV_VERSION="$(Renv-version-file-read "$RENV_VERSION_FILE" || true)" 8 | fi 9 | 10 | if [ -z "$RENV_VERSION" ] || [ "$RENV_VERSION" = "system" ]; then 11 | echo "system" 12 | exit 13 | fi 14 | 15 | RENV_VERSION_PATH="${RENV_ROOT}/versions/${RENV_VERSION}" 16 | 17 | if [ -d "$RENV_VERSION_PATH" ]; then 18 | echo "$RENV_VERSION" 19 | else 20 | echo "Renv: version \`$RENV_VERSION' is not installed" >&2 21 | exit 1 22 | fi 23 | -------------------------------------------------------------------------------- /libexec/Renv-version-origin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | [ -n "$RENV_DEBUG" ] && set -x 4 | 5 | if [ -n "$RENV_VERSION" ]; then 6 | echo "RENV_VERSION environment variable" 7 | else 8 | Renv-version-file 9 | fi 10 | -------------------------------------------------------------------------------- /libexec/Renv-versions: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | [ -n "$RENV_DEBUG" ] && set -x 4 | 5 | RENV_VERSION_NAME="$(Renv-version-name)" 6 | 7 | if [ "$1" = "--bare" ]; then 8 | hit_prefix="" 9 | miss_prefix="" 10 | print_version="$RENV_VERSION_NAME" 11 | else 12 | hit_prefix="* " 13 | miss_prefix=" " 14 | print_version="$(Renv-version)" 15 | fi 16 | 17 | for path in "${RENV_ROOT}/versions/"*; do 18 | if [ -d "$path" ]; then 19 | version="${path##*/}" 20 | 21 | if [ "$version" == "$RENV_VERSION_NAME" ]; then 22 | echo "${hit_prefix}${print_version}" 23 | else 24 | echo "${miss_prefix}${version}" 25 | fi 26 | fi 27 | done 28 | -------------------------------------------------------------------------------- /libexec/Renv-whence: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | [ -n "$RENV_DEBUG" ] && set -x 4 | 5 | # Provide Renv completions 6 | if [ "$1" = "--complete" ]; then 7 | echo --path 8 | exec Renv shims --short 9 | fi 10 | 11 | if [ "$1" = "--path" ]; then 12 | print_paths="1" 13 | shift 14 | else 15 | print_paths="" 16 | fi 17 | 18 | whence() { 19 | local command="$1" 20 | Renv-versions --bare | while read version; do 21 | path="$(Renv-prefix "$version")/bin/${command}" 22 | if [ -x "$path" ]; then 23 | [ "$print_paths" ] && echo "$path" || echo "$version" 24 | fi 25 | done 26 | } 27 | 28 | RENV_COMMAND="$1" 29 | if [ -z "$RENV_COMMAND" ]; then 30 | echo "usage: Renv whence [--path] COMMAND" >&2 31 | exit 1 32 | fi 33 | 34 | result="$(whence "$RENV_COMMAND")" 35 | [ -n "$result" ] && echo "$result" 36 | -------------------------------------------------------------------------------- /libexec/Renv-which: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | [ -n "$RENV_DEBUG" ] && set -x 4 | 5 | # Provide Renv completions 6 | if [ "$1" = "--complete" ]; then 7 | exec Renv shims --short 8 | fi 9 | 10 | expand_path() { 11 | if [ ! -d "$1" ]; then 12 | return 1 13 | fi 14 | 15 | local cwd="$(pwd)" 16 | cd "$1" 17 | pwd 18 | cd "$cwd" 19 | } 20 | 21 | remove_from_path() { 22 | local path_to_remove="$(expand_path "$1")" 23 | local result="" 24 | 25 | if [ -z "$path_to_remove" ]; then 26 | echo "${PATH}" 27 | return 28 | fi 29 | 30 | local paths 31 | IFS=: paths=($PATH) 32 | 33 | for path in "${paths[@]}"; do 34 | path="$(expand_path "$path" || true)" 35 | if [ -n "$path" ] && [ "$path" != "$path_to_remove" ]; then 36 | result="${result}${path}:" 37 | fi 38 | done 39 | 40 | echo "${result%:}" 41 | } 42 | 43 | RENV_VERSION="$(Renv-version-name)" 44 | RENV_COMMAND="$1" 45 | 46 | if [ -z "$RENV_COMMAND" ]; then 47 | echo "usage: Renv which COMMAND" >&2 48 | exit 1 49 | fi 50 | 51 | if [ "$RENV_VERSION" = "system" ]; then 52 | PATH="$(remove_from_path "${RENV_ROOT}/shims")" 53 | RENV_COMMAND_PATH="$(command -v "$RENV_COMMAND")" 54 | else 55 | RENV_COMMAND_PATH="${RENV_ROOT}/versions/${RENV_VERSION}/bin/${RENV_COMMAND}" 56 | fi 57 | 58 | for script in $(Renv-hooks which); do 59 | source "$script" 60 | done 61 | 62 | if [ -x "$RENV_COMMAND_PATH" ]; then 63 | echo "$RENV_COMMAND_PATH" 64 | else 65 | echo "Renv: $RENV_COMMAND: command not found" >&2 66 | 67 | versions="$(Renv-whence "$RENV_COMMAND" || true)" 68 | if [ -n "$versions" ]; then 69 | { echo 70 | echo "The \`$1' command exists in these R versions:" 71 | echo "$versions" | sed 's/^/ /g' 72 | echo 73 | } >&2 74 | fi 75 | 76 | exit 127 77 | fi 78 | --------------------------------------------------------------------------------