I would like to know how to make R treat an argument as a string even if it does not have quotes. Perhaps with unknown function bar
:
foo <- function(x) bar(a))
foo(a abadsf 23)
[1] "a abadsf 23"
Is this doing what you want?
printname <- function(x) deparse(substitute(x))
printname(foo)
[1] "foo"
printname(bar)
[1] "bar"
edit: This probably won't be considered acceptable, depending on where these values are coming from, but to include spaces you could try something like:
print.input = function(y=readline()) return(y)
usage in script:
print.input()
input with spaces
[1] "input with spaces"
printname(foo foo) Error: unexpected symbol in "printname(foo foo"
Apr 11, 2014 at 15:12
You can use quote, but this doesn't work with spaces.
deparse(quote(abc))
## [1] "abc"
deparse(quote(abc 1))
## Error: unexpected numeric constant in "deparse(quote(abc 1"
a="foo"
so that it was clear that I did not want to print "foo". Perhaps I should have just given(function(x) print(bar(a)))(a) [1] "a"