'R: Printing before keyring window opens
I'm writing an API and before anything starts, I'll check if a key is set in the keyring. If not, the user is prompted to fill in the required user and password. However, I couldn't manage that the printing statements to appear in the console before the keyring window opens. Am I doing somthing wrong?
API <- R6Class("API",
private = list(
m_usr = NULL,
m_pwd = NULL
),
public = list(
initialize = function() {
private$m_usr <- tryCatch(
{
keyring::key_get(service = "test-user", keyring = "R", username = Sys.getenv("USERNAME"))
},
error = function(...) {
print("No usr found in keyring R. Please set it up.")
keyring::key_set(service = "test-user", keyring = "R", username = Sys.getenv("USERNAME"))
return(keyring::key_get(service = "test-user", keyring = "R", username = Sys.getenv("USERNAME")))
}
)
private$m_pwd <- tryCatch(
{
keyring::key_get(service = "test-pwd", keyring = "R", username = Sys.getenv("USERNAME"))
},
error = function(...) {
print("No pwd found in keyring R. Please set it up.")
keyring::key_set(service = "test-pwd", keyring = "R", username = Sys.getenv("USERNAME"))
return(keyring::key_get(service = "test-pwd", keyring = "R", username = Sys.getenv("USERNAME")))
}
)
},
print = function(...) {
invisible(self)
}
)
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
