Skip to contents

Writes the credentials stored by pc_configure() to a .Renviron file so they persist across R sessions. Only variables that are currently set in the session are written; nothing else in .Renviron is touched.

Usage

pc_save_config(scope = c("user", "project"), .overwrite = FALSE)

Arguments

scope

Character. Where to write the .Renviron file:

  • "user": ~/.Renviron, applies to all R sessions for this user.

  • "project": ./.Renviron in the current working directory, applies to this project only. Recommended when different projects use different API keys.

.overwrite

Logical. If FALSE (default), variables that already exist in the target .Renviron are skipped, not replaced. Set to TRUE to update existing entries.

Value

Invisibly returns the path to the .Renviron file that was written, or NULL if nothing was written.

Details

In interactive sessions, the function always shows exactly what it will write (with API key values masked) and asks for confirmation before making any changes. In non-interactive sessions it proceeds without prompting, so use .overwrite = FALSE (the default) to avoid unintended overwrites in scripts.

Security

.Renviron stores credentials in plain text. For project-scoped files, ensure .Renviron is listed in .gitignore before committing. The function checks for this and warns if it is not.

Examples

if (FALSE) { # \dontrun{
pc_configure(email = "me@example.com", scopus_key = "my-key")
pc_save_config(scope = "project")
} # }