I would like to know if it is possible to pass a variable inside a string with R like in php. For example:
args <- commandArgs(TRUE)
variable1 <- args[1]
variable2 <- "I am argument:",variable1,"text continue"
variable2 <- paste0("I am argument:",variable1,"text continue")
There are variety of ways to get the output :
variable1 <- args[1]
1) Using sprintf as mentioned by @Roland
sprintf("I am argument: %s text continue",variable1)
2) Using glue
glue::glue("I am argument: {variable1} text continue")
3) a) str_c
stringr::str_c("I am argument:",variable1,"text continue")
b) stri_c
stringi::stri_c("I am argument:",variable1,"text continue")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With