Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get name of current user

What is a cross-platform way of getting the username of the current user in R? I am currently using

system('whoami', intern=TRUE)

However this assumes that the user has shell access, and that the whoami program is available. Is there a more native to get this information in R?

like image 938
Jeroen Ooms Avatar asked Jul 06 '13 06:07

Jeroen Ooms


People also ask

How do I find my current username?

Summary. You can make a Windows API (application programming interface) call to a Microsoft Windows DLL (dynamic-link library) to get the current user name. The current user name can be obtained by using the GetUserNameA function in ADVAPI32. DLL.

How do I get current user in Wordpress?

Getting all the information of current user in wordpress using the predefined function wp_get_current_user(); <? php $current_user = wp_get_current_user(); echo "Username :". $current_user->user_login; echo "Username :".

What is username in Linux?

There is no specific “username” command in Linux but there are other several sets of commands that let the user access the various users on the machine. 1. id: This command basically prints the information of real and effective user or in other words the current user.


1 Answers

I would do this :

 Sys.getenv("USERNAME")  ## works under windows

or better more robust:

 Sys.info()[["user"]]

But under unix-like system the result is sometimes different of system('whoami', intern=TRUE) :

whoami outputs the username that the user is working under, whereas $USER outputs the username that was used to login.

For example, if the user logged in as John and su into root, whoami displays root and echo $USER displays John. This is because the su command does not invoke a login shell by default.

like image 133
agstudy Avatar answered Oct 02 '22 10:10

agstudy