Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in R Programming by (7.3k points)

I have the following data frame with variable name "foo";

 > foo <-c(3,4);

What I want to do is to convert "foo" into a string. So that in a function I don't have to recreate another extra variables:

   output <- myfunc(foo)

   myfunc <- function(v1) {

     # do something with v1

     # so that it prints "FOO" when 

     # this function is called 

     #

     # instead of the values (3,4)

     return ()

   }

1 Answer

0 votes
by

You can use the deparse and the substitute functions to get the name of a function argument as follows:

myfun <- function(x) {

  deparse(substitute(x))

}

 myfun(foo)

[1] "foo"

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...