Skip to content

ED2: Allow negative numbers in custom ED2IN tag vectors#2361

Merged
tonygardella merged 3 commits intoPecanProject:developfrom
ashiklom:write-ed2in-bugfix
Jun 3, 2019
Merged

ED2: Allow negative numbers in custom ED2IN tag vectors#2361
tonygardella merged 3 commits intoPecanProject:developfrom
ashiklom:write-ed2in-bugfix

Conversation

@ashiklom
Copy link
Copy Markdown
Member

Allows <ed2in_tags> that are negative vectors to work. This is particularly relevant to soil depth (SLZ). For example:

<model>
  <ed2in_tags>
    <SLZ>-3.0, -2.7, -2, -1.5, -1, -0.5, -0.2, -0.1, -0.05</SLZ>
  </ed2in_tags>
</model>

Tagging @istfer and @serbinsh because you both work with ED.

This is particularly relevant to soil depth (SLZ).
are_numeric <- !is.na(try_numeric)
custom_tags[are_numeric] <- lapply(custom_tags[are_numeric], as.numeric)
custom_tags <- lapply(custom_tags,
tryCatch(as.numeric(x), warning = function(e) x))
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tryCatch(...) is a more elegant version of what I had on the left. Using lapply instead of vapply makes this robust to custom_tags that are vectors.

"([[:space:]]*,[[:space:]]*[[:digit:]]+.?[[:digit:]]*)+")
# Works for decimals, negatives, and arbitrary spacing: "1.3,2.6, -7.8 , 8.1"
numvec_rxp <- paste0("^ *-?[[:digit:]]+.?[[:digit:]]*",
"([[:space:]]*,[[:space:]]*-?[[:digit:]]+.?[[:digit:]]*)+")
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-? is regular expression syntax for "optional -".

@tonygardella tonygardella merged commit 0406c28 into PecanProject:develop Jun 3, 2019
@ashiklom ashiklom deleted the write-ed2in-bugfix branch June 11, 2019 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants