Using a Variable Where Quotes Are Needed in Function Argument

I'm not sure what you are trying to achieve, but couple of pointers.

As is tradition, first you should try to get your problem into reprex. This will help everyone, including yourself.

Second, what should be the result of the code mydata$Artist[x]? String? I imagine mydata is a dataframe and Artist is a column in a dataframe, so using mydata$Artist (btw, it is better to not use $ as it has multiple corner-cases that are likely to bite you down the road, instead you can use mydata[["Artist"]], for example) will return a vector that you can subset using integers, not strings. So x in your function signature can't be a string.

Finally, I'm fairly certain that you are trying to do is called quasiquotation or tidy evaluation, so you can use these name to search this forum or Google, if you like. There is a great webinar by Lionel Henry on this concept.

2 Likes