-
Notifications
You must be signed in to change notification settings - Fork 241
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
Code formatting + style cleanup in sipnet, workflow, ERA5 #3407
base: develop
Are you sure you want to change the base?
Conversation
Maybe Fixes Styling Section of #3280 |
@Sweetdevil144 This PR manually fixes the styling of a few files, but alas it doesn't implement the automated styling that #3280 wishes for. I'd still love to have that! |
@infotroph I just finished creating a script that automated styling using the |
Be aware that the last time someone tried to apply style rules to the entire PEcAn repo, there were a fairly large number of places where manual reversions to the original code were required. I'm not up for having to fight an automated stylizer on every PR (or even periodically). I also want to make sure anything that gets implemented doesn't increase the bar of frustration that new members of the team feel when trying to learn how to submit successful PRs (too much time is already spent making changes that are not in bits of code the individual touched) |
I'll say more about automated styling in #3280; For this thread let's focus on whether to merge these specific changes. |
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.
found some of the whitespace reformatting reduced readability considerably, especially when arguments to functions are shifted to be less indented than the function itself. Existing formatting makes it much easier to see what function is being called and what the arguments to that function are.
notes = "Test_Run", | ||
userid = user_id, | ||
username = "None", | ||
dates = Sys.Date() |
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 find the updated version is harder to read because the elements in the list don't line up with the parenthesis
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.
You're in good company -- I see hanging indents for function calls in many codebases and {lintr} accepts either style, however the tidyverse style guide is explicit about recommending against them for calls even though it accepts them for definitions. With the disclaimer that I conveniently like the single-indent style better anyway, I do see virtue in just following the style guide here.
Also a PEcAn specific point: A lot of our function calls have very long names and assign their results into deeply nested objects, so a hanging indent on something like some$list$sublist$item <- PEcAn.data.atmosphere::extract_thing_from_stuff(
is 75 characters (plus any nesting for the block it appears in) of whitespace before we even start writing arguments, so at my usual window widths many well-intentioned hanging indents tend to get mangled by linewrapping.
BTW, I think we agree it is important that all arguments get the same indentation. We have a lot of places we used to have nice alignments until we added namespaces to the call without adjusting the wrapped lines beneath them:
- somefun(a = foo,
+ somepkg::somefun(a = foo,
b = bar,
c = FALSE)
I'm happy to stipulate that these need to be fixed whatever style we're using.
dbname = "bety", | ||
driver = db_bety_driver, | ||
write = 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.
same. I do like the closing parenthesis on it's own line, but not indented at the same level as the original variable
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.
If I had my druthers I'd use single-indent but with the closing paren always on the same line as the last argument (like in hanging indent), but I seem to be alone one that one.
if (model.info$model_name == "LPJ-GUESS") { | ||
settings$run$inputs <- c( | ||
settings$run$inputs, | ||
list(soil = list(id = 1000000903)) |
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 what the aim or this overall function is, or where it's called from, but this sort of deeply-buried hard-coded hack is something we should really avoid. I know you didn't add this and are just reformatting it, but I wonder if we could take the opportunity to fix it? First, this bit won't work if we're moving away from BETY being required (and never would have worked on a machine lacking this input ID). Second, as we move towards more people passing in ensemble soil inputs, this is going to break things (especially if a soil input is already present, which the code never checks for)
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.
👍 to seeing something and taking the chance to fix it, but let's do it in a separate PR -- "Here's a big pile of whitespace changes with a few behavior changes mixed in" is my least favorite diff to review. I've made an issue for this in #3410
settings$pfts[[i]]$posteriorid, | ||
con, settings$host$name, | ||
return.all = TRUE | ||
) |
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.
Revert?
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 think some of this is diff getting confused (the pid <- ...
is still there, just shows in the next diff chunk), but IDK why styler didn't move "Posterior" down a line to match. That's a ding on my trust in the "just run styler::style_file() and it'll be good enough" theory.
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.
Figured it out below: styler accepts multiple unnamed arguments on the same line, and when the call has a mix of unnamed and named arguments the result seems to depend on the exact starting configuration.
}) %>% | ||
dplyr::bind_rows() %>% | ||
as.list())) | ||
) { |
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.
revert
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 think this is another place to rewrite and pull the site_info assignment out to its own line. In this case we don't even need to create a new temporary variable to do it!
host = settings$database$bety$host, | ||
user = settings$database$bety$user, | ||
password = settings$database$bety$password | ||
) |
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.
revert
site_info <- list( | ||
site_id = qry_results$id, site_name = qry_results$sitename, lat = qry_results$lat, | ||
lon = qry_results$lon, time_zone = qry_results$time_zone | ||
) |
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.
revert
outfolder = site_outFolder, | ||
start_date = site$start_date, | ||
end_date = site$end_date | ||
) |
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.
revert
years <- seq( | ||
lubridate::year(start_date), | ||
lubridate::year(end_date), | ||
1 |
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.
revert and fix the close parenthesis on the next line
Thanks for the review, @mdietze. I'll leave followup on some specific points inline, but I think the basic takeaway is that the bog-standard default output from {styler} isn't acceptable enough to adopt as it is. I'll see if I can find settings that come closer, but if not we should close this rather than try to manually massage individual lines. |
settings$pfts[[i]]$posteriorid, | ||
con, settings$host$name, | ||
return.all = TRUE | ||
) |
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.
Figured it out below: styler accepts multiple unnamed arguments on the same line, and when the call has a mix of unnamed and named arguments the result seems to depend on the exact starting configuration.
if (PEcAn.settings::is.MultiSettings(settings) || | ||
PEcAn.settings::is.Settings(settings)) { | ||
PEcAn.settings::is.Settings(settings)) { |
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.
Yeah, this one surprises me! I agree this is a readability loss, and would have expected it to force the opening brace onto its own line like for single-spaced function definitions:
if (
PEcAn.settings::is.MultiSettings(settings) ||
PEcAn.settings::is.Settings(settings)
) {
write <- settings$database$bety$write
...
}
...which I don't like as much as the hanging indent but it at least clearly separates the test conditions from the conditionally executed block.
mergeNC <- function( | ||
##title<< Aggregate data in netCDF files | ||
files ##<< character vector: names of the files to merge | ||
, outfile ##<< character: path to save the results files to. |
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 think this was me manually deleting these upon noting that the Roxygen tags are already there with [light rewordings of] all of these.
## description<< | ||
## This function aggregates time periods in netCDF files. Basically it is just a | ||
## wrapper around the respective cdo function. |
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.
## description<< | |
## This function aggregates time periods in netCDF files. Basically it is just a | |
## wrapper around the respective cdo function. |
@@ -1,60 +1,64 @@ | |||
#' Merge multiple NetCDF files into one | |||
#' | |||
#' @param files \code{character}. List of filepaths, which should lead to NetCDF files. | |||
#' |
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.
#' | |
#' | |
#' This function aggregates time periods in netCDF files. | |
#' Basically it is just a wrapper around the respective cdo function. | |
#' |
Description
Code style edits: None should change output, most are whitespace changes.
I was reading the code in write.configs.SIPNET and realized the uneven spacing around operators was slowing down my reading, and decided to run
styler::style_pkg()
on the whole sipnet and workflow packages while I was at it.I used styler's default styling settings to align with tidyverse style. I have some quibbles (e.g. it really wants the closing paren of a multi-line function call to be on its own line where I'd prefer it immediately after the last parameter), but none big enough to bother overriding.
Motivation and Context
Review Time Estimate
Types of changes
Checklist: