mardi 29 juin 2021

R: paste() a certain string only if bool is TRUE (conditional strings)?

I have the following code:

run_name = paste("run", "_", gsub(" ", "_", gsub(":", "", Sys.time())), sep="")
if(ROUNDING) run_name =  paste(run_name, "_R", sep="")

which generates a name like run_2021-06-29_101105 and for ROUNDING = TRUE it will add "_R": run_2021-06-29_101105_R

I'd like to include other parameters in the run_name and could do so with a line for each. But I vaguely remember (though maybe it was another programming language) that this is possible in one line with something like this (ROUNDING|"R"|"") :

run_name = paste("run", "_", gsub(" ", "_", gsub(":", "", Sys.time())), (ROUNDING|"R"|"") , sep="")

Is there such a thing (syntax for "conditional strings"?!) in R?

Aucun commentaire:

Enregistrer un commentaire