Skip to content
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

Merged
merged 9 commits into from
May 17, 2024
10 changes: 7 additions & 3 deletions models/sipnet/R/write.configs.SIPNET.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,12 @@ write.config.SIPNET <- function(defaults, trait.values, settings, run.id, inputs
jobsh <- gsub("@BINARY@", settings$model$binary, jobsh)
jobsh <- gsub("@REVISION@", settings$model$revision, jobsh)

jobsh <- gsub("@CPRUNCMD@", cpruncmd, jobsh)
jobsh <- gsub("@CPOUTCMD@", cpoutcmd, jobsh)
if(!is.identical(cpruncmd, character(0)) {
jobsh <- gsub("@CPRUNCMD@", cpruncmd, jobsh)
Copy link
Member

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)

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

Copy link
Collaborator Author

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.

Copy link
Member

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?

}
if(!is.identical(cpoutcmd, character(0)) {
jobsh <- gsub("@CPOUTCMD@", cpoutcmd, jobsh)
}
jobsh <- gsub("@RMOUTDIRCMD@", rmoutdircmd, jobsh)
jobsh <- gsub("@RMRUNDIRCMD@", rmrundircmd, jobsh)

Expand Down Expand Up @@ -630,4 +634,4 @@ remove.config.SIPNET <- function(main.outdir, settings) {
} else {
print("*** WARNING: Removal of files on remote host not yet implemented ***")
}
} # remove.config.SIPNET
} # remove.config.SIPNET