0

I'm not showing my actual code because it has many running parts, so let me just showcase what I am running into. I have this function:

paste <- function(d) {
        print(paste0(d,"_test", sep =""))
}

What I wanted returned would be if I did paste(advising) for example is "advising_test".

The reason I am not just doing paste("advising") is because in the function I am writing, advising needs to be used as both in quotes in order to name a particular object and needs to be used as the name of a dataframe that I am doing another function on. Therefore, I need to figure out how in the code I can paste the parameter with quotes, so I can use the term both ways.

vpatel
  • 43
  • 4

2 Answers2

1
paste <- function(d) {
        print(paste0(ensym(d),"_test", sep =""))
}

Edit : You can have a look at https://rlang.r-lib.org/reference/nse-defuse.html

A.Chrlt
  • 296
  • 2
  • 7
1

Use substitute . No packages are used.

mypaste <- function(d) print(paste0(substitute(d), "_test"))

# test
mypaste(advising)
## [1] "advising_test"
G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341