WISH: Sys.setlocale() to return value invisibly

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

WISH: Sys.setlocale() to return value invisibly

Henrik Bengtsson-5
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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: WISH: Sys.setlocale() to return value invisibly

Henrik Bengtsson-5
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
<[hidden email]> 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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel