[Rd] restoring LANGUAGE env variable within an R session

2023-06-26 Thread Ben Bolker
  I was playing around with the setting of the LANGUAGE variable and am 
wondering whether I'm missing something obvious about resetting the 
value to its original state once it's been set.  I seem to be able to 
reset the language for warnings/errors once, but not to change it a 
second time (or reset it) once it's been set ... ??


## default (no LANGUAGE set, English locale)
> sqrt(-1)
[1] NaN
Warning message:
In sqrt(-1) : NaNs produced
## no complaints, doesn't change (as expected)
> Sys.setenv(LANGUAGE = "en")
> sqrt(-1)
[1] NaN
Warning message:
In sqrt(-1) : NaNs produced

## change to German
> Sys.setenv(LANGUAGE = "de")
> sqrt(-1)
[1] NaN
Warnmeldung:
In sqrt(-1) : NaNs wurden erzeugt

## try to change to Spanish - no luck
## (this does work in a clean session)

> Sys.setenv(LANGUAGE = "es")
> sqrt(-1)
[1] NaN
Warnmeldung:
In sqrt(-1) : NaNs wurden erzeugt

## try resetting to blank
> Sys.setenv(LANGUAGE = "")
> sqrt(-1)
[1] NaN
Warnmeldung:
In sqrt(-1) : NaNs wurden erzeugt

## or back to English explicitly?
> Sys.setenv(LANGUAGE = "en")
> sqrt(-1)
[1] NaN
Warnmeldung:
In sqrt(-1) : NaNs wurden erzeugt
>

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] restoring LANGUAGE env variable within an R session

2023-06-26 Thread Dirk Eddelbuettel


Ben,

POSIX level / glibc level variables are set at process start and AGAIK cannot
really be altered after start.  They clearly work when set _before_ calling 
sqrt(-1):

$ LANGUAGE=es Rscript -e 'sqrt(-1)'
[1] NaN
Warning message:
In sqrt(-1) : Se han producido NaNs
$ LANGUAGE=de Rscript -e 'sqrt(-1)'
[1] NaN
Warnmeldung:
In sqrt(-1) : NaNs wurden erzeugt
$ 

I think the `callr` package can help you with this use from with R by
effectively spawning a new process for you. Or, lower-level, you can call
`system()` or `system2()` yourself and take care of the setup.

Cheers, Dirk

-- 
dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] restoring LANGUAGE env variable within an R session

2023-06-26 Thread Eric Berger
There is also some inconsistency.
Even though sqrt(-1) returns the warning/error about NaNs in German
after setting the language to Spanish, if you give the command
> messages()
it will respond in Spanish.



On Mon, Jun 26, 2023 at 4:39 PM Dirk Eddelbuettel  wrote:
>
>
> Ben,
>
> POSIX level / glibc level variables are set at process start and AGAIK cannot
> really be altered after start.  They clearly work when set _before_ calling 
> sqrt(-1):
>
> $ LANGUAGE=es Rscript -e 'sqrt(-1)'
> [1] NaN
> Warning message:
> In sqrt(-1) : Se han producido NaNs
> $ LANGUAGE=de Rscript -e 'sqrt(-1)'
> [1] NaN
> Warnmeldung:
> In sqrt(-1) : NaNs wurden erzeugt
> $
>
> I think the `callr` package can help you with this use from with R by
> effectively spawning a new process for you. Or, lower-level, you can call
> `system()` or `system2()` yourself and take care of the setup.
>
> Cheers, Dirk
>
> --
> dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org
>
> __
> 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] restoring LANGUAGE env variable within an R session

2023-06-26 Thread Ben Bolker
  That's reasonable, but I'm wondering why it works the *first* time 
it's called in a session. Is this just undefined behaviour (so I 
shouldn't be surprised whatever happens)?  Again,


$ Rscript -e 'sqrt(-1); Sys.setenv(LANGUAGE="es"); sqrt(-1)'
[1] NaN
Warning message:
In sqrt(-1) : NaNs produced
[1] NaN
Warning message:
In sqrt(-1) : Se han producido NaNs

  I should clarify that this really isn't that important for my 
workflow, it just seemed like an odd loose end.


Weirdly, I just discovered that Sys.setLanguage().  Don't know how it 
differs, but there's a bindtextdomain(NULL) call  there which may be the 
magic sauce ... ???


 sqrt(-1)
[1] NaN
Warning message:
In sqrt(-1) : NaNs produced
> Sys.setLanguage("de")
> sqrt(-1)
[1] NaN
Warnmeldung:
In sqrt(-1) : NaNs wurden erzeugt
> Sys.setLanguage("en")
> sqrt(-1)
[1] NaN
Warning message:
In sqrt(-1) : NaNs produced



On 2023-06-26 9:38 a.m., Dirk Eddelbuettel wrote:


Ben,

POSIX level / glibc level variables are set at process start and AGAIK cannot
really be altered after start.  They clearly work when set _before_ calling 
sqrt(-1):

 $ LANGUAGE=es Rscript -e 'sqrt(-1)'
 [1] NaN
 Warning message:
 In sqrt(-1) : Se han producido NaNs
 $ LANGUAGE=de Rscript -e 'sqrt(-1)'
 [1] NaN
 Warnmeldung:
 In sqrt(-1) : NaNs wurden erzeugt
 $

I think the `callr` package can help you with this use from with R by
effectively spawning a new process for you. Or, lower-level, you can call
`system()` or `system2()` yourself and take care of the setup.

Cheers, Dirk



--
Dr. Benjamin Bolker
Professor, Mathematics & Statistics and Biology, McMaster University
Director, School of Computational Science and Engineering
(Acting) Graduate chair, Mathematics & Statistics
> E-mail is sent at my convenience; I don't expect replies outside of 
working hours.


__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] restoring LANGUAGE env variable within an R session

2023-06-26 Thread Sebastian Meyer

Translated strings are cached.
I'd recommend to use the

• New partly experimental Sys.setLanguage() utility, solving the
  main problem of PR#18055.

introduced in R 4.2.0.

Best,

Sebastian Meyer


Am 26.06.23 um 15:15 schrieb Ben Bolker:

I was playing around with the setting of the LANGUAGE variable and am
wondering whether I'm missing something obvious about resetting the
value to its original state once it's been set.  I seem to be able to
reset the language for warnings/errors once, but not to change it a
second time (or reset it) once it's been set ... ??

## default (no LANGUAGE set, English locale)
  > sqrt(-1)
[1] NaN
Warning message:
In sqrt(-1) : NaNs produced
## no complaints, doesn't change (as expected)
  > Sys.setenv(LANGUAGE = "en")
  > sqrt(-1)
[1] NaN
Warning message:
In sqrt(-1) : NaNs produced

## change to German
  > Sys.setenv(LANGUAGE = "de")
  > sqrt(-1)
[1] NaN
Warnmeldung:
In sqrt(-1) : NaNs wurden erzeugt

## try to change to Spanish - no luck
## (this does work in a clean session)

  > Sys.setenv(LANGUAGE = "es")
  > sqrt(-1)
[1] NaN
Warnmeldung:
In sqrt(-1) : NaNs wurden erzeugt

## try resetting to blank
  > Sys.setenv(LANGUAGE = "")
  > sqrt(-1)
[1] NaN
Warnmeldung:
In sqrt(-1) : NaNs wurden erzeugt

## or back to English explicitly?
  > Sys.setenv(LANGUAGE = "en")
  > sqrt(-1)
[1] NaN
Warnmeldung:
In sqrt(-1) : NaNs wurden erzeugt
  >

__
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] restoring LANGUAGE env variable within an R session

2023-06-26 Thread Ben Bolker
  Thanks, this is exactly PR#18055. Should have looked (but assumed I 
was probably just overlooking something ...)


On 2023-06-26 10:02 a.m., Sebastian Meyer wrote:

Translated strings are cached.
I'd recommend to use the

     • New partly experimental Sys.setLanguage() utility, solving the
   main problem of PR#18055.

introduced in R 4.2.0.

Best,

 Sebastian Meyer


Am 26.06.23 um 15:15 schrieb Ben Bolker:

    I was playing around with the setting of the LANGUAGE variable and am
wondering whether I'm missing something obvious about resetting the
value to its original state once it's been set.  I seem to be able to
reset the language for warnings/errors once, but not to change it a
second time (or reset it) once it's been set ... ??

## default (no LANGUAGE set, English locale)
  > sqrt(-1)
[1] NaN
Warning message:
In sqrt(-1) : NaNs produced
## no complaints, doesn't change (as expected)
  > Sys.setenv(LANGUAGE = "en")
  > sqrt(-1)
[1] NaN
Warning message:
In sqrt(-1) : NaNs produced

## change to German
  > Sys.setenv(LANGUAGE = "de")
  > sqrt(-1)
[1] NaN
Warnmeldung:
In sqrt(-1) : NaNs wurden erzeugt

## try to change to Spanish - no luck
## (this does work in a clean session)

  > Sys.setenv(LANGUAGE = "es")
  > sqrt(-1)
[1] NaN
Warnmeldung:
In sqrt(-1) : NaNs wurden erzeugt

## try resetting to blank
  > Sys.setenv(LANGUAGE = "")
  > sqrt(-1)
[1] NaN
Warnmeldung:
In sqrt(-1) : NaNs wurden erzeugt

## or back to English explicitly?
  > Sys.setenv(LANGUAGE = "en")
  > sqrt(-1)
[1] NaN
Warnmeldung:
In sqrt(-1) : NaNs wurden erzeugt
  >

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


--
Dr. Benjamin Bolker
Professor, Mathematics & Statistics and Biology, McMaster University
Director, School of Computational Science and Engineering
(Acting) Graduate chair, Mathematics & Statistics
> E-mail is sent at my convenience; I don't expect replies outside of 
working hours.


__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] dir.exists returns FALSE on Symlink directory

2023-06-26 Thread Dipterix Wang
I hope I'm not asking a stupid question... If I symlink a directory, is symlink 
considered as directory in R? If so, why `dir.exists` returns FALSE on 
directory?

I understand symlink is essentially a file, but functionally a symlink to 
directory is no different to the directory itself, but a directory is also 
essentially a file.

Is there any way that allow me to check if a symlink is linked to directory in 
base R, like `dir.exists(..., symlink_ok = TRUE)`?

Thanks,
Dipterix
__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] dir.exists returns FALSE on Symlink directory

2023-06-26 Thread Ivan Krylov
В Mon, 26 Jun 2023 10:26:07 -0400
Dipterix Wang  пишет:

> If I symlink a directory, is symlink considered as directory in R?

It seems to work, at least on GNU/Linux:

# (on this system, /var/lock is a symbolic link pointing to /run/lock/)
system('ls -l /var/lock')
# lrwxrwxrwx 1 root root <...> /var/lock -> /run/lock
dir.exists('/var/lock')
# [1] TRUE

> If so, why `dir.exists` returns FALSE on directory?

Which operating system? Judging by your User-Agent, it must be some
version of macOS. Can you provide the output of `ls -l` on the symbolic
link?

-- 
Best regards,
Ivan

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] dir.exists returns FALSE on Symlink directory

2023-06-26 Thread Stephen H. Dawson, DSL via R-devel
It sounds like either R as a whole or the R session does not have 
permission to view the directory.



*Stephen Dawson, DSL*
/Executive Strategy Consultant/
Business & Technology
+1 (865) 804-3454
http://www.shdawson.com


On 6/26/23 11:07, Ivan Krylov wrote:

В Mon, 26 Jun 2023 10:26:07 -0400
Dipterix Wang  пишет:


If I symlink a directory, is symlink considered as directory in R?

It seems to work, at least on GNU/Linux:

# (on this system, /var/lock is a symbolic link pointing to /run/lock/)
system('ls -l /var/lock')
# lrwxrwxrwx 1 root root <...> /var/lock -> /run/lock
dir.exists('/var/lock')
# [1] TRUE


If so, why `dir.exists` returns FALSE on directory?

Which operating system? Judging by your User-Agent, it must be some
version of macOS. Can you provide the output of `ls -l` on the symbolic
link?



__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] dir.exists returns FALSE on Symlink directory

2023-06-26 Thread Serguei Sokol via R-devel

Le 26/06/2023 à 16:26, Dipterix Wang a écrit :

I hope I'm not asking a stupid question...
Many think that there is no such thing as "stupid question". However, 
this one looks more appropriate for r-help list, does not it?



  If I symlink a directory, is symlink considered as directory in R? If so, why 
`dir.exists` returns FALSE on directory?

I understand symlink is essentially a file, but functionally a symlink to 
directory is no different to the directory itself, but a directory is also 
essentially a file.

Is there any way that allow me to check if a symlink is linked to directory in 
base R, like `dir.exists(..., symlink_ok = TRUE)`?

What about :

dir.exists(Sys.readlink("your_link"))

?

Best,
Serguei.



Thanks,
Dipterix
__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel



--
Serguei Sokol
Ingenieur de recherche INRAE

Cellule Mathématiques
TBI, INSA/INRAE UMR 792, INSA/CNRS UMR 5504
135 Avenue de Rangueil
31077 Toulouse Cedex 04

tel: +33 5 61 55 98 49
email: so...@insa-toulouse.fr
https://www.toulouse-biotechnology-institute.fr/en/plateformes-plateaux/cellule-mathematiques/

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] dir.exists returns FALSE on Symlink directory

2023-06-26 Thread Serguei Sokol via R-devel

Le 26/06/2023 à 17:17, Serguei Sokol a écrit :

Le 26/06/2023 à 16:26, Dipterix Wang a écrit :

I hope I'm not asking a stupid question...
Many think that there is no such thing as "stupid question". However, 
this one looks more appropriate for r-help list, does not it?


  If I symlink a directory, is symlink considered as directory in R? 
If so, why `dir.exists` returns FALSE on directory?


I understand symlink is essentially a file, but functionally a 
symlink to directory is no different to the directory itself, but a 
directory is also essentially a file.


Is there any way that allow me to check if a symlink is linked to 
directory in base R, like `dir.exists(..., symlink_ok = TRUE)`?

What about :

dir.exists(Sys.readlink("your_link"))

Or even better:

file_test("-d", "your_real_dir_or_simlink_to_dir")

which returns TRUE for both a real dir and a simlink to a dir.

Best,
Serguei.



?

Best,
Serguei.



Thanks,
Dipterix
__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel






--
Serguei Sokol
Ingenieur de recherche INRAE

Cellule Mathématiques
TBI, INSA/INRAE UMR 792, INSA/CNRS UMR 5504
135 Avenue de Rangueil
31077 Toulouse Cedex 04

tel: +33 5 61 55 98 49
email: so...@insa-toulouse.fr
https://www.toulouse-biotechnology-institute.fr/en/plateformes-plateaux/cellule-mathematiques/

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] dir.exists returns FALSE on Symlink directory

2023-06-26 Thread Dipterix Wang
Thanks!

I think Sys.readlink resolved my issue. Indeed I found a permission issue. I 
will post my questions to r-help next time.

Best,
Dipterix

> On Jun 26, 2023, at 11:17 AM, Serguei Sokol  wrote:
> 
> Le 26/06/2023 à 16:26, Dipterix Wang a écrit :
>> I hope I'm not asking a stupid question...
> Many think that there is no such thing as "stupid question". However, this 
> one looks more appropriate for r-help list, does not it?
> 
>>  If I symlink a directory, is symlink considered as directory in R? If so, 
>> why `dir.exists` returns FALSE on directory?
>> 
>> I understand symlink is essentially a file, but functionally a symlink to 
>> directory is no different to the directory itself, but a directory is also 
>> essentially a file.
>> 
>> Is there any way that allow me to check if a symlink is linked to directory 
>> in base R, like `dir.exists(..., symlink_ok = TRUE)`?
> What about :
> 
> dir.exists(Sys.readlink("your_link"))
> 
> ?
> 
> Best,
> Serguei.
> 
>> 
>> Thanks,
>> Dipterix
>> __
>> R-devel@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
> 
> 
> -- 
> Serguei Sokol
> Ingenieur de recherche INRAE
> 
> Cellule Mathématiques
> TBI, INSA/INRAE UMR 792, INSA/CNRS UMR 5504
> 135 Avenue de Rangueil
> 31077 Toulouse Cedex 04
> 
> tel: +33 5 61 55 98 49
> email: so...@insa-toulouse.fr
> https://www.toulouse-biotechnology-institute.fr/en/plateformes-plateaux/cellule-mathematiques/
> 

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel