passwords {keychain}R Documentation

Functions to access password in user's keychain


getPassword retireves a password stored in the keychain

setPassword adds or modifies a password stored in the keychain

rmPassword removes a password from the kaychain


getPassword(service, user = NULL, quiet = FALSE, keychain = NULL)
setPassword(service, user = NULL, password, keychain = NULL)
 rmPassword(service, user = NULL, keychain = NULL)



Name (arbitrary string) identifying the service


User name (if NULL the current login name of the user is used)


if FALSE then the function fails in case no password is found, if TRUE then NULL is returned in that case. Note that the function can still fail for other reasons (invalid parameters, keychain or denied access) regardless of the quiet flag.


new password (single string)


Keychain to operate on. If NULL then the default user keychain is used (recommended). In the current implementation that is the only valid value.


The above functions access and modify passwords in the current user's keychain. A keychain is a secure storage of information that can be locked and ulocked by the user. The functions above manipulate passwords associated with (service, user) pairs.

The actual storage and method of determining user authorization is system-dependent. The current implementation uses the Security framework to work with users' keychain.


getPassword: the currently stored password (decrypted) or NULL of quiet=TRUE and no password was found.

setPassword: previous password or NULL if the password was just created.

rmPassword: previous password


The current implementation uses default system keychain where supported. The system may ask the user for authentication to open the keychain.

The passwords are stored as generic passwords. Note that the actual service name used at the system level is prefixed with an R-specific prefix to prevent abuse by reading other passwords (such as your internet passwords etc.). However, malicious users could modify the package to allow arbitrary access, so be wary of the source from which you install this package.

Please note that once you authorize R to access the keychain, it may be open for subsequent access.


Simon Urbanek


  pwd <- getPassword("foo", quiet=TRUE)
  if (is.null(pwd)) cat("foo doesn't exist yet\n")
  setPassword("foo",, "bar")
  pwd <- getPassword("foo")

[Package keychain version 0.1-0 Index]