How to create a function that attaches the input to the end of an existing string in the function?


Let’s say I have this function:

f <- function(input){
  name <- "hello_"

I want to be able to use


and have name be renamed to "hello_world".

Important is that I don’t want the input to be a string. So the solution should not involve f("world").

>Solution :

Use substitute like this:

f <- function(input) paste0("hello_", substitute(input))
## [1] "hello_world"

Leave a Reply Cancel reply