-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from gongcastro/test
Format code
- Loading branch information
Showing
21 changed files
with
1,161 additions
and
1,078 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,3 @@ reduce <- function(.x, .f, ..., .init) { | |
f <- function(x, y) .f(x, y, ...) | ||
Reduce(f, .x, init = .init) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,69 +16,69 @@ | |
#' it is assumed to be the same as `formr_email`. | ||
#' @param password Character string with the password to formr (`NULL` by | ||
#' default). | ||
#' | ||
#' | ||
#' @return Logical. `TRUE` if Google and formr authentication was successful, | ||
#' `FALSE` if authentication of any of the two failed. | ||
#' | ||
#' | ||
#' @examples | ||
#' \dontrun{bvq_connect()} | ||
#' | ||
#' \dontrun{ | ||
#' bvq_connect() | ||
#' } | ||
#' | ||
bvq_connect <- function(google_email = NULL, | ||
password = NULL) { | ||
formr_email <- "[email protected]" | ||
|
||
# ask for email in console is everything is NULL | ||
if (is.null(google_email)) google_email <- formr_email | ||
|
||
if (is.null(password)) { | ||
password <- Sys.getenv("FORMR_PWD", unset = NA) | ||
if (is.na(password)) { | ||
cli_abort("Please, provide a password") | ||
} | ||
formr_email <- "[email protected]" | ||
|
||
# ask for email in console is everything is NULL | ||
if (is.null(google_email)) google_email <- formr_email | ||
|
||
if (is.null(password)) { | ||
password <- Sys.getenv("FORMR_PWD", unset = NA) | ||
if (is.na(password)) { | ||
cli_abort("Please, provide a password") | ||
} | ||
|
||
# if key exists, use it to log in | ||
tryCatch( | ||
suppressWarnings( | ||
formr::formr_connect( | ||
email = formr_email, | ||
password = password, | ||
host = "https://formr.org/" | ||
) | ||
), | ||
error = function(e) { | ||
cli_abort( | ||
strwrap( | ||
prefix = " ", | ||
initial = "", | ||
"Could not connect to {.url https://formr.org/}. Please check your internet connection or make sure you have set the right formr password in a {.file .Renviron} file, under the name {.envvar FORMR_PWD}." | ||
) | ||
) | ||
} | ||
) | ||
|
||
# check if Google credentials exists, ask for them if not | ||
if (!gs4_has_token()) { | ||
tryCatch( | ||
suppressWarnings({ | ||
googlesheets4::gs4_auth( | ||
email = google_email, | ||
token = Sys.getenv("GOOGLE_TOKEN", unset = NA) | ||
) | ||
}), | ||
error = function(e) { | ||
cli_abort( | ||
strwrap( | ||
prefix = " ", | ||
initial = "", | ||
"Could not connect to Google.\ | ||
Please check your internet connection or \ | ||
grant the necessary permissions." | ||
) | ||
) | ||
} | ||
} | ||
|
||
# if key exists, use it to log in | ||
tryCatch( | ||
suppressWarnings( | ||
formr::formr_connect( | ||
email = formr_email, | ||
password = password, | ||
host = "https://formr.org/" | ||
) | ||
), | ||
error = function(e) { | ||
cli_abort( | ||
strwrap( | ||
prefix = " ", | ||
initial = "", | ||
"Could not connect to {.url https://formr.org/}. Please check your internet connection or make sure you have set the right formr password in a {.file .Renviron} file, under the name {.envvar FORMR_PWD}." | ||
) | ||
) | ||
} | ||
|
||
invisible(googlesheets4::gs4_has_token()) | ||
) | ||
|
||
# check if Google credentials exists, ask for them if not | ||
if (!gs4_has_token()) { | ||
tryCatch( | ||
suppressWarnings({ | ||
googlesheets4::gs4_auth( | ||
email = google_email, | ||
token = Sys.getenv("GOOGLE_TOKEN", unset = NA) | ||
) | ||
}), | ||
error = function(e) { | ||
cli_abort( | ||
strwrap( | ||
prefix = " ", | ||
initial = "", | ||
"Could not connect to Google. Please check your internet connection or grant the necessary permissions." | ||
) | ||
) | ||
} | ||
) | ||
} | ||
|
||
invisible(googlesheets4::gs4_has_token()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.