Skip to content

Commit 2ba5e83

Browse files
committed
Update vignettes/credential-scraping.Rmd
Add option to get username from API_USER env var. Add calling instructions.
1 parent 759c4aa commit 2ba5e83

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

vignettes/credential-scraping.Rmd

+21-3
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,35 @@ dbDisconnect(source_conn)
117117

118118
### Scraping one user's API tokens
119119

120-
Scraping one user's API tokens and putting them in a new, local sqlite DB for use.
120+
Scraping one user's API tokens and putting them in a new, local sqlite DB for use.
121+
122+
You must provide the username in the API_USER environment variable or on the command line. To specify it on the command line via `Rscript` and specify a REDCap username. e.g.
123+
124+
```sh
125+
Rscript scrape_one_user.R jane_doe
126+
```
121127

122128
```{r, eval = FALSE}
123129
library(redcapcustodian)
124130
library(DBI)
125131
library(tidyverse)
126132
library(dotenv)
127133
128-
# get the username provided on the command line
134+
# Get the username provided on the command line if one is provided.
135+
# Otherwise, get the username form the environment.
136+
# Otherwise, exit.
129137
args <- commandArgs(trailingOnly = TRUE)
130-
username <- args
138+
if (length(args) > 0) {
139+
# Use the command line argument
140+
username <- args
141+
} else if (Sys.getenv("API_USER") != "") {
142+
# Use the environment variable
143+
username <- Sys.getenv("API_USER")
144+
} else {
145+
# Exit
146+
warning("Please provide an username that whose API tokens you want to read either on the command line or via the API_USER environment variable. No action taken.")
147+
quit()
148+
}
131149
132150
# Creates the credentials file if one does not exists.
133151
# Otherwise it deletes the credentials file

0 commit comments

Comments
 (0)