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.