Query, set, delete list keys in a keyring

These functions manipulate keys in a keyring. You can think of a keyring as a secure key-value store.

key_get(service, username = NULL, keyring = NULL)

key_get_raw(service, username = NULL, keyring = NULL)

key_set(service, username = NULL, keyring = NULL)

key_set_with_value(service, username = NULL, password = NULL, keyring = NULL)

key_set_with_raw_value(service, username = NULL, password = NULL, keyring = NULL)

key_delete(service, username = NULL, keyring = NULL)

key_list(service = NULL, keyring = NULL)


Service name, a character scalar.


Username, a character scalar, or NULL if the key is not associated with a username.


For systems that support multiple keyrings, specify the name of the keyring to use here. If NULL, then the default keyring is used. See also has_keyring_support().


The secret to store. For key_set, it is read from the console, interactively. key_set_with_value can be also used in non-interactive mode.


key_get queries a key from the keyring.

key_get_raw queries a key and returns it as a raw vector. Most credential stores allow storing a byte sequence with embedded null bytes, and these cannot be represented as traditional null bytes terminated strings. If you don't know whether the key contains an embedded null, it is best to query it with key_get_raw instead of key_get.

key_set sets a key in the keyring. The contents of the key is read interactively from the terminal.

key_set_with_value is the non-interactive pair of key_set, to set a key in the keyring.

key_set_raw_with_value sets a key to a byte sequence from a raw vector.

key_delete deletes a key.

key_list lists all keys of a keyring, or the keys for a certain service (if service is not NULL).


key_get returns a character scalar, the password or other confidential information that was stored in the key.

key_list returns a list of keys, i.e. service names and usernames, in a data frame.

  • key_get
  • key_get_raw
  • key_set
  • key_set_with_value
  • key_set_with_raw_value
  • key_delete
  • key_list
# These examples use the default keyring, and they are interactive,
# so, we don't run them by default
# }
key_set("R-keyring-test-service", "donaldduck")
key_get("R-keyring-test-service", "donaldduck")
if (has_keyring_support()) key_list(service = "R-keyring-test-service")
key_delete("R-keyring-test-service", "donaldduck")

## This is non-interactive, assuming that that default keyring
## is unlocked
key_set_with_value("R-keyring-test-service", "donaldduck",
                   password = "secret")
key_get("R-keyring-test-service", "donaldduck")
if (has_keyring_support()) key_list(service = "R-keyring-test-service")
key_delete("R-keyring-test-service", "donaldduck")
# }
Documentation reproduced from package keyring, version 1.1.0, License: MIT + file LICENSE

Community examples

Looks like there are no examples yet.