You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
convert.expr() mis-splits expressions containing ^, - in parentheses, or [ ] #4216
PEcAn.utils::convert.expr() builds a regular-expression character class from the operator characters it finds and splits on it. Characters that are special inside [...] break the class, so derived-variable expressions with ^, (a-b) or [ ] give wrong variable names or an error.
a=b-c and Diff=GPP-NEE work only because - is the only operator there.
Cause
split.chars is every non-[a-zA-Z0-9_.] character in the expression, pasted into "[" ... "]". A leading ^ negates the class, (-) becomes a range, and [ / ] are special.
Impact
The result feeds read.output(variables = ...). Callers include get.results(), run.ensemble.analysis(), run.sensitivity.analysis(), model2netcdf.ED2() and modules/assim.batch. A derived variable such as <variable>Diff=(GPP-NEE)*2</variable> is read with the wrong names.
Proposed fix
Split on the fixed class directly, strsplit(deri.eqn, "[^a-zA-Z0-9_.]"), and drop empty entries. This gives the same result for the cases that already worked (a plain variable name is returned unchanged), is a net deletion of code, and needs only a unit test for the four cases above. I have a branch ready with the test; happy to send a PR if wanted.
Confession: I don't understand what use case convert.expr is intended to support, and even though it gets called by multiple functions I can't find an example of a workflow that actually needs it. At some point I proposed to delete it and was told we couldn't, but I no longer remember why not.
Activity
madhavzanwar commentedon Nov 2, 2026
@infotroph I have a fix and a test ready for this: https://github.com/madhavzanwar/pecan/tree/GH-4216-convert-expr-special-chars (net deletion of ~6 lines; the new test fails on current develop, and all of test.utils.R passes with the fix). Happy to open the PR whenever you’d like.
Merge branch 'develop' into PecanProjectGH-4216-convert-expr-special-…
madhavzanwar commentedon Nov 19, 2026
@infotroph PR is up: #4257
infotroph commentedon Nov 22, 2026
Confession: I don't understand what use case
convert.expris intended to support, and even though it gets called by multiple functions I can't find an example of a workflow that actually needs it. At some point I proposed to delete it and was told we couldn't, but I no longer remember why not.@dlebauer can you give some history here?
Merge upstream develop into PecanProjectGH-4216-convert-expr-special-…
Merge upstream develop into PecanProjectGH-4216-convert-expr-special-…