Re: [Rd] Fwd: Using existing envars in Renviron on friendly Windows
Thanks for the suggestions, I've updated the documentation. Tomas On 11/3/21 11:30 AM, Tomas Kalibera wrote: On 11/3/21 1:37 AM, Henrik Bengtsson wrote: Oh, I see, I misunderstood. Thanks for clarifying. One more thing, to mix-and-match environment variables and strings with escaped characters, while mimicking how POSIX shells does it, by using strings with double and single quotes. For example, with: $ cat .Renviron APPDATA='C:\Users\foobar\AppData\Roaming' R_LIBS_USER="${APPDATA}"'\R-library' we get: $ Rscript --no-init-file --quiet -e 'cat(sprintf("R_LIBS_USER=[%s]\n", Sys.getenv("R_LIBS_USER")))' R_LIBS_USER=[C:\Users\foobar\AppData\Roaming\R-library] and $ source .Renviron $ echo "R_LIBS_USER=[${R_LIBS_USER}]" R_LIBS_USER=[C:\Users\foobar\AppData\Roaming\R-library] Yes, that could be mentioned explicitly as well. Tomas /Henrik On Sun, Oct 31, 2021 at 2:59 AM Tomas Kalibera wrote: On 10/31/21 2:55 AM, Henrik Bengtsson wrote: ... If one still needed backslashes, they could then be entered in single quotes, e.g. VAR='c:\users'. I don't think it matters whether you use single or double quotes - both will work. Here's a proof of concept on Linux with R 4.1.1: $ cat ./.Renviron A=C:\users B='C:\users' C="C:\users" $ Rscript -e "Sys.getenv(c('A', 'B', 'C'))" A B C "C:users" "C:\\users" "C:\\users" Yes, but as I wrote "I think the Renviron files should be written in a way so that they would work the same in a POSIX shell". This is why single quotes. With double quotes, backslashes are interpreted differently from a POSIX shell. Tomas /Henrik On Wed, Oct 27, 2021 at 11:45 AM Tomas Kalibera wrote: 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 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 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 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 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" >>
Re: [Rd] Fwd: Using existing envars in Renviron on friendly Windows
On 11/3/21 1:37 AM, Henrik Bengtsson wrote: Oh, I see, I misunderstood. Thanks for clarifying. One more thing, to mix-and-match environment variables and strings with escaped characters, while mimicking how POSIX shells does it, by using strings with double and single quotes. For example, with: $ cat .Renviron APPDATA='C:\Users\foobar\AppData\Roaming' R_LIBS_USER="${APPDATA}"'\R-library' we get: $ Rscript --no-init-file --quiet -e 'cat(sprintf("R_LIBS_USER=[%s]\n", Sys.getenv("R_LIBS_USER")))' R_LIBS_USER=[C:\Users\foobar\AppData\Roaming\R-library] and $ source .Renviron $ echo "R_LIBS_USER=[${R_LIBS_USER}]" R_LIBS_USER=[C:\Users\foobar\AppData\Roaming\R-library] Yes, that could be mentioned explicitly as well. Tomas /Henrik On Sun, Oct 31, 2021 at 2:59 AM Tomas Kalibera wrote: On 10/31/21 2:55 AM, Henrik Bengtsson wrote: ... If one still needed backslashes, they could then be entered in single quotes, e.g. VAR='c:\users'. I don't think it matters whether you use single or double quotes - both will work. Here's a proof of concept on Linux with R 4.1.1: $ cat ./.Renviron A=C:\users B='C:\users' C="C:\users" $ Rscript -e "Sys.getenv(c('A', 'B', 'C'))" A B C "C:users" "C:\\users" "C:\\users" Yes, but as I wrote "I think the Renviron files should be written in a way so that they would work the same in a POSIX shell". This is why single quotes. With double quotes, backslashes are interpreted differently from a POSIX shell. Tomas /Henrik On Wed, Oct 27, 2021 at 11:45 AM Tomas Kalibera wrote: 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 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 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 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 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
Re: [Rd] Fwd: Using existing envars in Renviron on friendly Windows
Oh, I see, I misunderstood. Thanks for clarifying. One more thing, to mix-and-match environment variables and strings with escaped characters, while mimicking how POSIX shells does it, by using strings with double and single quotes. For example, with: $ cat .Renviron APPDATA='C:\Users\foobar\AppData\Roaming' R_LIBS_USER="${APPDATA}"'\R-library' we get: $ Rscript --no-init-file --quiet -e 'cat(sprintf("R_LIBS_USER=[%s]\n", Sys.getenv("R_LIBS_USER")))' R_LIBS_USER=[C:\Users\foobar\AppData\Roaming\R-library] and $ source .Renviron $ echo "R_LIBS_USER=[${R_LIBS_USER}]" R_LIBS_USER=[C:\Users\foobar\AppData\Roaming\R-library] /Henrik On Sun, Oct 31, 2021 at 2:59 AM Tomas Kalibera wrote: > > > On 10/31/21 2:55 AM, Henrik Bengtsson wrote: > >> ... If one still needed backslashes, > >> they could then be entered in single quotes, e.g. VAR='c:\users'. > > I don't think it matters whether you use single or double quotes - > > both will work. Here's a proof of concept on Linux with R 4.1.1: > > > > $ cat ./.Renviron > > A=C:\users > > B='C:\users' > > C="C:\users" > > > > $ Rscript -e "Sys.getenv(c('A', 'B', 'C'))" > >A B C > >"C:users" "C:\\users" "C:\\users" > > Yes, but as I wrote "I think the Renviron files should be written in a > way so that they would work the same in a POSIX shell". This is why > single quotes. With double quotes, backslashes are interpreted > differently from a POSIX shell. > > Tomas > > > > > > /Henrik > > > > On Wed, Oct 27, 2021 at 11:45 AM Tomas Kalibera > > wrote: > >> > >> 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 > >>> 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 > >>> 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 > >>> 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 wrote: > >>> >> >>> > >>> >> AVAR=${APPDATA}/foo/bar > >>> >> > >>>
Re: [Rd] Fwd: Using existing envars in Renviron on friendly Windows
On 10/31/21 2:55 AM, Henrik Bengtsson wrote: ... If one still needed backslashes, they could then be entered in single quotes, e.g. VAR='c:\users'. I don't think it matters whether you use single or double quotes - both will work. Here's a proof of concept on Linux with R 4.1.1: $ cat ./.Renviron A=C:\users B='C:\users' C="C:\users" $ Rscript -e "Sys.getenv(c('A', 'B', 'C'))" A B C "C:users" "C:\\users" "C:\\users" Yes, but as I wrote "I think the Renviron files should be written in a way so that they would work the same in a POSIX shell". This is why single quotes. With double quotes, backslashes are interpreted differently from a POSIX shell. Tomas /Henrik On Wed, Oct 27, 2021 at 11:45 AM Tomas Kalibera wrote: 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 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 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 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 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-dev
Re: [Rd] Fwd: Using existing envars in Renviron on friendly Windows
> ... If one still needed backslashes, > they could then be entered in single quotes, e.g. VAR='c:\users'. I don't think it matters whether you use single or double quotes - both will work. Here's a proof of concept on Linux with R 4.1.1: $ cat ./.Renviron A=C:\users B='C:\users' C="C:\users" $ Rscript -e "Sys.getenv(c('A', 'B', 'C'))" A B C "C:users" "C:\\users" "C:\\users" /Henrik On Wed, Oct 27, 2021 at 11:45 AM Tomas Kalibera wrote: > > > 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 > > 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 > > 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 > > 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 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 li
Re: [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 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 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 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 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
Re: [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 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 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 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 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
Re: [Rd] Fwd: Using existing envars in Renviron on friendly Windows
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 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 > 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 > > > 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 > > >> 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 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
Re: [Rd] Fwd: Using existing envars in Renviron on friendly Windows
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 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 > > 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 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 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
Re: [Rd] Fwd: Using existing envars in Renviron on friendly Windows
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 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 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 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
Re: [Rd] Fwd: Using existing envars in Renviron on friendly Windows
Perhaps a small update to ?.Renviron would be in order to mention that... On Fri, Oct 15, 2021 at 6:43 PM Michał Bojanowski 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 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 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
Re: [Rd] Fwd: Using existing envars in Renviron on friendly Windows
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 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 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
Re: [Rd] Fwd: Using existing envars in Renviron on friendly Windows
Sorry for the noise! I wasn't supposed to send my previous message. On Fri, 15 Oct 2021 16:44:28 +0200 Michał Bojanowski 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
Re: [Rd] Fwd: Using existing envars in Renviron on friendly Windows
On Fri, 15 Oct 2021 16:44:28 +0200 Michał Bojanowski 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, that -- Best regards, Ivan __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Fwd: Using existing envars in Renviron on friendly Windows
On 15/10/2021 10:44 a.m., Michał Bojanowski wrote: Dear colleagues, I would be grateful if somebody could explain and perhaps help work around the following. I have .Renviron with, say: AVAR=${APPDATA}/foo/bar Which is a documented way of referring to existing environment variables. Now, with that in R I'm getting: I think in your example, AVAR would be set using AVAR=C:\Users\mbojanowski\AppData\Roaming/foo/bar When I export that value in a bash shell (on a Mac, not Windows), I get the same thing as you saw: $ printenv AVAR C:UsersmbojanowskiAppDataRoaming/foo/bar Here R was not involved at all, this is the shell eating the backslashes. So I suppose R is following the same rules as bash (or maybe getting bash or sh to handle .Renviron). Those rules are that the single backslashes are treated as escapes, and so they are dropped and the following character is preserved: https://www.gnu.org/software/bash/manual/html_node/Escape-Character.html . I think you don't have a lot of choice here: if you don't have control over how an environment variable is being set, then don't try to use it in an expansion in .Renviron. If you do have control, then avoid using backslashes. So this would be fine: APPDATA=C:/Users/mbojanowski/AppData/Roaming AVAR=${APPDATA}/foo/bar but your APPDATA setting needs to be handled in some other way, e.g. in .Rprofile instead of .Renviron. Duncan Murdoch Sys.getenv("APPDATA")# That works OK [1] "C:\\Users\\mbojanowski\\AppData\\Roaming" so OK, but: Sys.getenv("AVAR") [1] "C:UsersmbojanowskiAppDataRoaming/foo/bar" So all the (back)slashes are gone from APPDATA. Does processing ${} removes the backslashes? I could not find anything on that in R Windows FAQ nor on the web. Thanks in advance! Michal __ 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
[Rd] Fwd: Using existing envars in Renviron on friendly Windows
Dear colleagues, I would be grateful if somebody could explain and perhaps help work around the following. I have .Renviron with, say: 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" So all the (back)slashes are gone from APPDATA. Does processing ${} removes the backslashes? I could not find anything on that in R Windows FAQ nor on the web. Thanks in advance! Michal __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel