Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed some global variables in PEcAn.DB package #2971

Merged
merged 20 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion base/db/R/get.trait.data.pft.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ get.trait.data.pft <- function(pft, modeltype, dbfiles, dbcon, trait.names,
dplyr::mutate_if(is.character, ~dplyr::na_if(., ""))

# get the priors
prior.distns <- PEcAn.DB::query.priors(pft = pftid, trstr = PEcAn.utils::vecpaste(trait.names), con = dbcon)
prior.distns <- PEcAn.DB::query.priors(
pft = pftid,
trstr = PEcAn.utils::vecpaste(trait.names),
con = dbcon)
prior.distns <- prior.distns[which(!rownames(prior.distns) %in% names(pft$constants)),]
traits <- rownames(prior.distns)

Expand Down
2 changes: 1 addition & 1 deletion base/db/R/query.dplyr.R
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ load_data_single_run <- function(bety, workflow_id, run_id) {
ncfile <- list.files(path = outputfolder, pattern = "\\.nc$", full.names = TRUE)[1]
nc <- ncdf4::nc_open(ncfile)

globalDF <- tidyr::gather(out, key = var_name, value = vals, names(out)[names(out) != "posix"]) %>%
globalDF <- tidyr::gather(out, key = "var_name", value = "vals", names(out)[names(out) != "posix"]) %>%
dplyr::rename(dates = .data$posix)
globalDF$workflow_id <- workflow_id
globalDF$run_id <- run_id
Expand Down
13 changes: 3 additions & 10 deletions base/db/R/query.prior.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,9 @@ query.priors <- function(pft, trstr = NULL, con = NULL, ...){
if (is.null(con)) {
params <- list(...)
if (!length(params)) {
PEcAn.logger::logger.warn(paste0(
"No connection (`con`) or params (`...`) specified. ",
'Trying to connect from `settings[[c("database", "bety")]]`.'
))
if (!exists("settings")) {
PEcAn.logger::logger.severe(
"`settings` object not found. Unable to connect to database."
)
}
params <- settings[[c("database", "bety")]]
PEcAn.logger::logger.severe(
"No connection (`con`) specified and no connection parameters given in `...`.",
"Unable to connect to database.")
}
con <- db.open(params)
on.exit(db.close(con), add = TRUE)
Expand Down
2 changes: 1 addition & 1 deletion base/db/R/utils_db.R
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ db.exists <- function(params, write = TRUE, table = NA) {
}

#check table's privilege about read and write permission
user.permission <<- tryCatch({
user.permission <- tryCatch({
invisible(db.query(
paste0("SELECT privilege_type FROM information_schema.role_table_grants ",
"WHERE grantee='", params$user,
Expand Down