[R-SIG-Mac] Identifying computer from R

Uwe Ligges ||gge@ @end|ng |rom @t@t|@t|k@tu-dortmund@de
Fri Jun 2 10:36:05 CEST 2023



On 02.06.2023 09:05, Martin Maechler wrote:
>>>>>> Simon Urbanek
>>>>>>      on Mon, 29 May 2023 07:36:46 -0500 writes:
> 
>      > Dennis,
>      > PS1 is an internal shell environment variable (modifying prompt) which has nohting to do with R (and nothing to do with the computer name by default) so it won't be set in R, only in a shell.
>      > If you want the machine's hostname you'd typically use system("hostname") in R.
> 
> Or  Sys.info()[["nodename"]]


Even Microsoft provides 'hostname', hence I believe this is pretty save 
to use. But then the result is not identical:

c(Sys.getenv("COMPUTERNAME"), Sys.info()[["nodename"]], 
system("hostname", intern=TRUE))
[1] "CRANWIN3" "CRANWIN3" "CRANwin3"

Where the GUI agrees with the system("hostname") version and what I 
defined when setting up the machine.
Note that the nodename in the network is not case sensitive, hence it is 
right, too.
Conclusion: Which version is preferred depends on the actual task.

Best,
Uwe


> which I think should be slightly more portable, no?
> 
> Best,
> Martin
> 
> 
> 
>      > Cheers,
>      > Simon
> 
> 
>      >> On 26/05/2023, at 17:15, Dennis Fisher <fisher using plessthan.com> wrote:
>      >>
>      >> R 4.2.3
>      >> OS X
>      >>
>      >> Colleagues
>      >>
>      >> Interesting (minor) problem.  I have code that I run automatically on two different computers.  The code runs from Dropbox so there is not separate code for each computer.
>      >>
>      >> In order to identify which computer is running the code, I was hoping to do something like:
>      >> Sys.getenv(SOMETHING)
>      >>
>      >> In a terminal window:
>      >> echo $PS1
>      >> returns the prompt on that particular computer.
>      >>
>      >> However, when I attempt to access that from R, I am not successful.  For example:
>      >>
>      >> In a terminal:
>      >> echo $PS1
>      >> returns:
>      >> PET\!>
>      >>
>      >> In R:
>      >> Sys.getenv("PS1")
>      >> returns:
>      >> ""
>      >>
>      >> In R:
>      >> system("echo $PS1")
>      >> returns an empty line.
>      >>
>      >> A solution to this immediate problem (how to obtain that environment variable in R) or any other clever way to identify a particular computer would be much appreciated.
>      >>
>      >> Dennis
>      >>
>      >>
>      >> Dennis Fisher MD
>      >> P < (The "P Less Than" Company)
>      >> Phone / Fax: 1-866-PLessThan (1-866-753-7784)
>      >> www.PLessThan.com
>      >>
>      >> _______________________________________________
>      >> R-SIG-Mac mailing list
>      >> R-SIG-Mac using r-project.org
>      >> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
>      >>
> 
> _______________________________________________
> R-SIG-Mac mailing list
> R-SIG-Mac using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac



More information about the R-SIG-Mac mailing list