-
Notifications
You must be signed in to change notification settings - Fork 235
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
[Bug fix] : Fixed gsub
issue in write.config.SIPNET
#3275
Conversation
jobsh <- gsub("@CPRUNCMD@", cpruncmd, jobsh) | ||
jobsh <- gsub("@CPOUTCMD@", cpoutcmd, jobsh) | ||
if(!is.identical(cpruncmd, character(0)) { | ||
jobsh <- gsub("@CPRUNCMD@", cpruncmd, jobsh) |
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.
Couple questions:
- are we sure that if these variables aren't defined in the pecan.xmxl that they'll be set to character(0)?
- If these variables don't exist, are we sure the job.sh will run correctly with the text of these tags left in the shell script? looking at the template job, it seems like they should be removed (i.e. gsubbed with an empty string)
@CPRUNCMD@
If the right thing to do is gsub with an empty string, and the is.identical is assuming the default is an empty string, this begs the question of why the default case is failing
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.
The code segment responsible to set the value of cpruncmd
is write.configs.SIPNET.R#L76-L77.
Here since we don't set the value for settings$host$rabbitmq$cpfcmd
as part of settings file that means on addressing this variable we get NULL
. gsub
returns a character(0)
value when the target string is NULL
.
Basically the line transforms to :
cpruncmd <- gsub("@OUTDIR@", settings$host$rundir, NULL)
which is why a check for this is needed in place.
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.
@meetagrawal09 I agree with your diagnosis, but I think the issue should be fixed on lines 76-77 rather than here. Maybe that could be something like cpruncmd <- gsub("@OUTDIR@", settings$host$rundir, settings$host$rabbitmq$cpfcmd %||% "")
, then the replacements on lines 105-106 remain unconditional?
@@ -73,6 +73,7 @@ write.config.SIPNET <- function(defaults, trait.values, settings, run.id, inputs | |||
cpruncmd <- cpoutcmd <- rmoutdircmd <- rmrundircmd <- "" | |||
if (!is.null(settings$host$rabbitmq)) { | |||
#rsync cmd from remote to local host. | |||
settings$host$rabbitmq$cpfcmd <- if(settings$host$rabbitmq$cpfcmd == NULL) "" else settings$host$rabbitmq$cpfcmd |
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.
@meetagrawal09 this syntax doesn't work in R. First, if(settings$host$rabbitmq$cpfcmd == NULL)
throws an "argument is of length zero" error if the variable is NULL and should be replaced with is.null(). Second, the if ... else
syntax should be replaced with the ifelse()
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.
Or the null-coalescing operator %||%
as I showed above—it’s made for exactly this case
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.
Don't know but this operator did not work for me. Shows me the below error.
Error in settings$host$rabbitmq$cpfcmd %||% "" : could not find 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.
Oh, hm.
(1) You'll need to import it[1] from rlang with #' @importFrom rlang %||%
or just copy in the definition: function (x, y) { if (is.null(x)) y else x}
...
(2) ...which reminds me that %||%
only works on scalars. @mdietze does your point about ifelse
mean cpfcmd
might have legnth >1? If so my advice was bad to start with and ifelse
seems cleaner.
[1] (%||%
has been added to base R in 4.4.0, so a few version bumps from now we'll be able to use it with no import)
Description
Fixed issues with local deployment for
SIPNET
model.The variables
cpruncmd
andcpoutcmd
were added towrite.config.SIPNET
to extend it for cloud based PEcAn deployment. On a local deployment setup the workflow for SIPNET model was breaking with the below error :The error arises since local
pecan.xml
does not containsettings$host$rabbitmq$cpfcmd
andsettings$host$rabbitmq$cpfcmd
which is used to setcpruncmd
andcpoutcmd
in thewrite.config.SIPNET
file.Review Time Estimate
Types of changes
Checklist: