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?
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.
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 :".
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With