You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: vignettes/credential-scraping.Rmd
+21-3
Original file line number
Diff line number
Diff line change
@@ -117,17 +117,35 @@ dbDisconnect(source_conn)
117
117
118
118
### Scraping one user's API tokens
119
119
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
+
```
121
127
122
128
```{r, eval = FALSE}
123
129
library(redcapcustodian)
124
130
library(DBI)
125
131
library(tidyverse)
126
132
library(dotenv)
127
133
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.
129
137
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
+
}
131
149
132
150
# Creates the credentials file if one does not exists.
0 commit comments