Two comments/suggestions: 1. What about recommending to always quote the value in Renviron files, e.g. ABC="Hello world" and DEF="${APPDATA}/R-library"? This should a practice that works on all platforms.
2. What about having readRenviron() escapes strings it imports via environment variables? See example below. Is there ever a use case where someone wants/needs, or even rely on, the current behavior? (I would even like to argue the current behavior is a design bug that should be fixed.) As an analogue from the shell world, Bash escapes its input. To illustrate the latter, with: A=C:\\ABC B=${A} C="${A}" or equivalently: A="C:\ABC" B=${A} C="${A}" we currently get: $ Rscript -e "Sys.getenv(c('A', 'B', 'C'))" A B C "C:\\ABC" "C:ABC" "C:\\ABC" If base::readRenviron() would escape "input" environment variables, we would get identical values for both 'B' and 'C', which I think is what most people would expect. To be clear, this is a problem that occur on all platforms, but it's more likely to be revealed on MS Windows since paths uses backslashes, but you could image a Linux user using something like A="Hello\nworld\n" and would also be surprised about the above behavior, when they end up with B="Hellonworldn". /Henrik On Wed, Oct 20, 2021 at 7:31 AM Michał Bojanowski <michal2...@gmail.com> wrote: > > 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? > > On Mon, Oct 18, 2021 at 5:02 PM Tomas Kalibera <tomas.kalib...@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 <michal2...@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.r...@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 <michal2...@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@r-project.org mailing list > > > https://stat.ethz.ch/mailman/listinfo/r-devel > > ______________________________________________ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel