-
Notifications
You must be signed in to change notification settings - Fork 228
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
Style cleanup for db/R/*.R
scripts
#1091
Conversation
Ran through formatR::tidy_dir with arrow=TRUE and indent=2; made sure all if blocks have braces. Tried to make sure formatR didn’t make things too jaggy. Substituted `seq_len`, `seq_along`, and `paste0`, and `file.path` as necessary. Made sure all functions end with an explicit `return`.
Throwing similar errors to #1042 |
Hmm. The test code that's failing ( |
db/R/dbfiles.R
Outdated
} | ||
if (is.null(inputid)) { | ||
invisible(data.frame()) | ||
return(invisible(data.frame())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Significant change: before an invisible data.frame
was being created but not used, and execution continued. Now it's returned (as I thought was the intention).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure the return is needed. I thought R would return the last computed value, in this case either of the invisible statements in the if statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@robkooper agreed, it's not; but @mdietze and others have expressed preference for explicit return
s, so I've started doing that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I sort of agree with them, I had always thought that invisible would return as well, until I realized some of my code does not work. So I do think having an explicit return(invisible()) is a good thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tonygardella can we make sure we add to the styleguide section that we are using explicit returns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@robkooper Got it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried to tag places where Travis was unhappy. get.id's colname vs colnames definitely needs fixing. In terms of the failed tests, they all fail due to "expired PostgreSQLConnection" starting with Error: citations table exists and has >= 1 columns. This makes me think that something's closing the connection prematurely
##' } | ||
get.id <- function(table, colnames, values, con, create=FALSE, dates=FALSE){ | ||
get.id <- function(table, colnames, values, con, create = FALSE, dates = FALSE) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Second argument here is colnames (plural). In some of the calls to this function we're using colname, others are using colnames, and others aren't passing by name. Need to make this consistent. colname is clearly wrong.
@@ -125,19 +124,18 @@ query.yields <- function(trait = 'yield', spstr, extra.columns='', con=NULL, ... | |||
##' @author Carl Davidson, Ryan Kelly | |||
##' @export | |||
##--------------------------------------------------------------------------------------------------# | |||
append.covariate<-function(data, column.name, covariates.data){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Travis says "Must have a \description"
@@ -172,33 +169,32 @@ query.covariates<-function(trait.ids, con = NULL, ...){ | |||
##' @param new.temp the reference temperature for the scaled traits. Curerntly 25 degC | |||
##' @param missing.temp the temperature assumed for traits with no covariate found. Curerntly 25 degC | |||
##' @author Carl Davidson, David LeBauer, Ryan Kelly | |||
arrhenius.scaling.traits <- function(data, covariates, temp.covariates, new.temp=25, missing.temp=25){ | |||
arrhenius.scaling.traits <- function(data, covariates, temp.covariates, new.temp = 25, | |||
missing.temp = 25) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Travis says "Must have a \description"
data <- append.covariate(data, 'canopy_layer', | ||
covariates[covariates$name == 'canopy_layer',]) | ||
data <- data[data$canopy_layer >= 0.66 | is.na(data$canopy_layer),] | ||
filter.sunleaf.traits <- function(data, covariates) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Travis says "Must have a \description"
covariate.query <- paste("select covariates.trait_id, covariates.level,variables.name", | ||
"from covariates left join variables on variables.id = covariates.variable_id", | ||
"where trait_id in (",vecpaste(trait.ids),")") | ||
query.covariates <- function(trait.ids, con = NULL, ...) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Travis says "Must have a \description"
path <- file.path(dbfile$file_path,dbfile$file_name) | ||
cmd <- paste0("file.exists( '",path,"')") | ||
remote.execute.R(cmd,machine.host,verbose=TRUE) | ||
query.file.path <- function(input.id, host_name, con) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Travis says "Must have a \description"
db/R/query.format.vars.R
Outdated
@@ -6,107 +6,113 @@ | |||
##' | |||
##' @author Betsy Cowdery , Ankur Desai | |||
##' | |||
query.format.vars <- function(input.id,con,format.id){ | |||
|
|||
query.format.vars <- function(input.id, con, format.id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Travis says "Must have a \description"
@@ -5,14 +5,17 @@ | |||
##' @export | |||
##' | |||
##' @author Betsy Cowdery | |||
##' | |||
query.site <- function(site.id,con){ | |||
query.site <- function(site.id, con) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Travis says "Must have a \description"
@@ -236,25 +231,23 @@ filter.sunleaf.traits <- function(data, covariates){ | |||
##' @seealso used with \code{\link{jagify}}; | |||
##' @export | |||
rename.jags.columns <- function(data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Travis says "Must have a \description"
# find appropriate pft | ||
pftid <- get.id("pfts", "name", pft, con) | ||
if (is.null(pftid)) { | ||
invisible(data.frame()) | ||
return(invisible(data.frame())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Significant change: before an invisible data.frame
was being created but not used, and execution continued. Now it's returned (as I thought was the intention).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch
if (is.null(posteriorid)) { | ||
invisible(data.frame()) | ||
return(invisible(data.frame())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same.
db/R/dbfiles.R
Outdated
if (is.null(hostid)) { | ||
invisible(data.frame()) | ||
return(invisible(data.frame())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And again.
db/R/dbfiles.R
Outdated
logger.warn("multiple files found for", id, "returned; using the first one found") | ||
invisible(file.path(files[1, 'file_path'], files[1, 'file_name'])) | ||
return(invisible(file.path(files[1, "file_path"], files[1, "file_name"]))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also.
if (is.null(hostid)) { | ||
invisible(NA) | ||
return(invisible(NA)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last one. Significant change: before an invisible data.frame
was being created but not used, and execution continued. Now it's returned (as I thought was the intention).
Thanks, Mike. I can add placeholder |
@bpbond conflict on get.trait.data.R |
# Conflicts: # modules/data.atmosphere/R/load.cfmet.R # modules/data.atmosphere/R/met2CF.NARR.R # modules/data.atmosphere/R/temporal.downscaling.R
Just tried rebuilding this PR in light of all the other changes. Still fails but gets much further (SIPNET test case)
@robkooper or others might know better than me, but this error suggests that some function is closing the db connection that shouldn't, and thus downstream code is getting passed a closed connection. |
@bpbond might be worth a try to just resolve conflicts and update to see if changes elsewhere have resolved some of the issues we're seeing here. I'll just be here slouching and watching DOE's ergonomics videos while I wait for that (HR finally caught me!) |
You have fun with that! |
Conflict resolution. I hope.
The packages all install, but a test fails (same as above):
|
@bpbond I was looking through old PRs. I was going to ask if you wanted to resolve the conflicts, then took a look, saw GitHub has a new way to resolve conflicts in the browser and got started. It wouldn't let me save a draft so I went through and tried to resolve everything. This package is pretty complex, what with pasting SQL queries together and all, and I have no desire to debug any errors that may arise so I am still uncertain if it is worth merging this. (time will be better spent porting to dplyr ... ). So if anything non-trivial pops up I would suggest we close the PR and either re-format the package from master branch or move on and never look back. In any case, thanks again for doing so much work into making PEcAn's formatting more consistent. |
Sorry I let this drop. If there are other architectural or science things you guys would like me to consider/look at, feel free to ping me if useful. Ben |
Cleaning up and updating "Using Git" page
Revert "Cleaning up and updating "Using Git" page"
At this point it would be easier to re-run the clean-up described in the original PR comment than to resolve remaining conflicts and hope that these and previously resolved conflicts are correct. |
Ran through formatR::tidy_dir with arrow=TRUE and indent=2; made sure all if blocks have braces. Tried to make sure formatR didn’t make things too jaggy. Substituted
seq_len
,seq_along
, andpaste0
, andfile.path
as necessary. Made sure all functions end with an explicitreturn
.