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
1 change: 1 addition & 0 deletions models/sipnet/R/write.configs.SIPNET.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

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.

Copy link
Member

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

Copy link
Collaborator Author

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 "%||%"

Copy link
Member

@infotroph infotroph May 17, 2024

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)

cpruncmd <- gsub("@OUTDIR@", settings$host$rundir, settings$host$rabbitmq$cpfcmd)
cpruncmd <- gsub("@OUTFOLDER@", rundir, cpruncmd)

Expand Down
Loading