Reputation: 953
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"
Upvotes: 3
Views: 5562
Reputation: 388907
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")
Upvotes: 1
Reputation: 10375
variable2 <- paste0("I am argument:",variable1,"text continue")
Upvotes: 7