Skip to content

Commit

Permalink
Merge pull request PecanProject#2971 from nanu1605/db_global_variable
Browse files Browse the repository at this point in the history
Fixed some global variables in PEcAn.DB package
  • Loading branch information
mdietze authored Aug 1, 2022
2 parents 8b55da9 + 1d3ae6c commit 1cc3d7f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
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

0 comments on commit 1cc3d7f

Please sign in to comment.