Martin Maechler
2021-Oct-21 15:18 UTC
[Rd] Fwd: Using existing envars in Renviron on friendly Windows
>>>>> Micha? Bojanowski >>>>> on Wed, 20 Oct 2021 16:31:08 +0200 writes:> Hello Tomas, > Yes, that's accurate although rather terse, which is perhaps the > reason why I did not realize it applies to my case. > How about adding something in the direction of: > 1. Continuing the cited paragraph with: > In particular, on Windows it may be necessary to quote references to > existing environment variables, especially those containing file paths > (which include backslashes). For example: `"${WINVAR}"`. > 2. Add an example (not run): > # On Windows do quote references to variables containing paths, e.g.: > # If APPDATA=C:\Users\foobar\AppData\Roaming > # to point to a library tree inside APPDATA in .Renviron use > R_LIBS_USER="${APPDATA}"/R-library > Incidentally the last example is on backslashes too. > What do you think? I agree that adding an example really helps a lot in such cases, in my experience, notably if it's precise enough to be used +/- directly. > On Mon, Oct 18, 2021 at 5:02 PM Tomas Kalibera <tomas.kalibera at gmail.com> wrote: >> >> >> On 10/15/21 6:44 PM, Micha? Bojanowski wrote: >> > Perhaps a small update to ?.Renviron would be in order to mention that... >> >> Would you have a more specific suggestion how to update the >> documentation? Please note that it already says >> >> "?value? is then processed in a similar way to a Unix shell: in >> particular the outermost level of (single or double) quotes is stripped, >> and backslashes are removed except inside quotes." >> >> Thanks, >> Tomas >> >> > On Fri, Oct 15, 2021 at 6:43 PM Micha? Bojanowski <michal2992 at gmail.com> wrote: >> >> Indeed quoting works! Kevin suggested the same, but he didnt reply to the list. >> >> Thank you all! >> >> Michal >> >> >> >> On Fri, Oct 15, 2021 at 6:40 PM Ivan Krylov <krylov.r00t at gmail.com> wrote: >> >>> Sorry for the noise! I wasn't supposed to send my previous message. >> >>> >> >>> On Fri, 15 Oct 2021 16:44:28 +0200 >> >>> Micha? Bojanowski <michal2992 at gmail.com> wrote: >> >>> >> >>>> AVAR=${APPDATA}/foo/bar >> >>>> >> >>>> Which is a documented way of referring to existing environment >> >>>> variables. Now, with that in R I'm getting: >> >>>> >> >>>> Sys.getenv("APPDATA") # That works OK >> >>>> [1] "C:\\Users\\mbojanowski\\AppData\\Roaming" >> >>>> >> >>>> so OK, but: >> >>>> >> >>>> Sys.getenv("AVAR") >> >>>> [1] "C:UsersmbojanowskiAppDataRoaming/foo/bar" >> >>> Hmm, a function called by readRenviron does seem to remove backslashes, >> >>> but not if they are encountered inside quotes: >> >>> >> >>> https://github.com/r-devel/r-svn/blob/3f8b75857fb1397f9f3ceab6c75554e1a5386adc/src/main/Renviron.c#L149 >> >>> >> >>> Would AVAR="${APPDATA}"/foo/bar work? >> >>> >> >>> -- >> >>> Best regards, >> >>> Ivan >> > ______________________________________________ >> > R-devel at r-project.org mailing list >> > https://stat.ethz.ch/mailman/listinfo/r-devel > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel
Tomas Kalibera
2021-Oct-27 18:45 UTC
[Rd] Fwd: Using existing envars in Renviron on friendly Windows
On 10/21/21 5:18 PM, Martin Maechler wrote:>>>>>> Micha? Bojanowski >>>>>> on Wed, 20 Oct 2021 16:31:08 +0200 writes: > > Hello Tomas, > > Yes, that's accurate although rather terse, which is perhaps the > > reason why I did not realize it applies to my case. > > > How about adding something in the direction of: > > > 1. Continuing the cited paragraph with: > > In particular, on Windows it may be necessary to quote references to > > existing environment variables, especially those containing file paths > > (which include backslashes). For example: `"${WINVAR}"`. > > > 2. Add an example (not run): > > > # On Windows do quote references to variables containing paths, e.g.: > > # If APPDATA=C:\Users\foobar\AppData\Roaming > > # to point to a library tree inside APPDATA in .Renviron use > > R_LIBS_USER="${APPDATA}"/R-library > > > Incidentally the last example is on backslashes too. > > > > What do you think? > > I agree that adding an example really helps a lot in such cases, > in my experience, notably if it's precise enough to be used +/- directly.Yes, I agree as well. I think the Renviron files should be written in a way so that they would work the same in a POSIX shell, so e.g. VAR="${VAR0}" or VAR="${VAR0}/subdir" are the recommended ways to preserve backslashes in VAR0. It is better to use forward slashes in string literals, e.g. VAR="c:/users". If one still needed backslashes, they could then be entered in single quotes, e.g. VAR='c:\users'. The currently implemented parsing of Renviron files differs in a number of details from POSIX shells, some are documented and some are not. Relying only on the documented behavior that is the same as in POSIX shells is the best choice for future compatibility. Tomas> > > > On Mon, Oct 18, 2021 at 5:02 PM Tomas Kalibera <tomas.kalibera at gmail.com> wrote: > >> > >> > >> On 10/15/21 6:44 PM, Micha? Bojanowski wrote: > >> > Perhaps a small update to ?.Renviron would be in order to mention that... > >> > >> Would you have a more specific suggestion how to update the > >> documentation? Please note that it already says > >> > >> "?value? is then processed in a similar way to a Unix shell: in > >> particular the outermost level of (single or double) quotes is stripped, > >> and backslashes are removed except inside quotes." > >> > >> Thanks, > >> Tomas > >> > >> > On Fri, Oct 15, 2021 at 6:43 PM Micha? Bojanowski <michal2992 at gmail.com> wrote: > >> >> Indeed quoting works! Kevin suggested the same, but he didnt reply to the list. > >> >> Thank you all! > >> >> Michal > >> >> > >> >> On Fri, Oct 15, 2021 at 6:40 PM Ivan Krylov <krylov.r00t at gmail.com> wrote: > >> >>> Sorry for the noise! I wasn't supposed to send my previous message. > >> >>> > >> >>> On Fri, 15 Oct 2021 16:44:28 +0200 > >> >>> Micha? Bojanowski <michal2992 at gmail.com> wrote: > >> >>> > >> >>>> AVAR=${APPDATA}/foo/bar > >> >>>> > >> >>>> Which is a documented way of referring to existing environment > >> >>>> variables. Now, with that in R I'm getting: > >> >>>> > >> >>>> Sys.getenv("APPDATA") # That works OK > >> >>>> [1] "C:\\Users\\mbojanowski\\AppData\\Roaming" > >> >>>> > >> >>>> so OK, but: > >> >>>> > >> >>>> Sys.getenv("AVAR") > >> >>>> [1] "C:UsersmbojanowskiAppDataRoaming/foo/bar" > >> >>> Hmm, a function called by readRenviron does seem to remove backslashes, > >> >>> but not if they are encountered inside quotes: > >> >>> > >> >>> https://github.com/r-devel/r-svn/blob/3f8b75857fb1397f9f3ceab6c75554e1a5386adc/src/main/Renviron.c#L149 > >> >>> > >> >>> Would AVAR="${APPDATA}"/foo/bar work? > >> >>> > >> >>> -- > >> >>> Best regards, > >> >>> Ivan > >> > ______________________________________________ > >> > R-devel at r-project.org mailing list > >> > https://stat.ethz.ch/mailman/listinfo/r-devel > > > ______________________________________________ > > R-devel at r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-devel