Henrik Bengtsson
2018-Mar-20 21:11 UTC
[Rd] WISH: Sys.setlocale() to return value invisibly
Contrary to, say, Sys.setenv(), Sys.setlocale() returns it's value
visibly. This means that if you for instance add:
Sys.setlocale("LC_COLLATE", "C")
to your .Rprofile file, it will print:
[1] "C"
at startup. The workaround is to wrap the call in invisible(), but I'd
argue that any "setter" function should return invisibly.
Some more details:
> withVisible(Sys.setlocale("LC_COLLATE", "C"))
$value
[1] "C"
$visible
[1] TRUE
> withVisible(Sys.setenv(FOO = "C"))
$value
[1] TRUE
$visible
[1] FALSE
/Henrik
Henrik Bengtsson
2020-Mar-25 17:17 UTC
[Rd] WISH: Sys.setlocale() to return value invisibly
I case someone runs into this topic. I just found the following comment from 2012 on BugZilla explaining why Sys.setlocale() does *not* return invisibly contrary to most++ other setters in R: PR#15128: Sys.setlocale() - return previous setting invisibly? Brian Ripley on 2012-12-09 16:53:43 UTC:> It was a deliberate decision. Unlike options() the locale is usually set at startup and it is major thing to change it in a session--and it is usually only done recording the previous value to return to. The author certainly wanted to see what he was changing from in a session.https://bugs.r-project.org/bugzilla/show_bug.cgi?id=15128#c1 /Henrik On Tue, Mar 20, 2018 at 2:11 PM Henrik Bengtsson <henrik.bengtsson at gmail.com> wrote:> > Contrary to, say, Sys.setenv(), Sys.setlocale() returns it's value > visibly. This means that if you for instance add: > > Sys.setlocale("LC_COLLATE", "C") > > to your .Rprofile file, it will print: > > [1] "C" > > at startup. The workaround is to wrap the call in invisible(), but I'd > argue that any "setter" function should return invisibly. > > Some more details: > > > withVisible(Sys.setlocale("LC_COLLATE", "C")) > $value > [1] "C" > > $visible > [1] TRUE > > > withVisible(Sys.setenv(FOO = "C")) > $value > [1] TRUE > > $visible > [1] FALSE > > /Henrik