Does R have quote-like operators like Perl's qw()?
No, but you can write it yourself:
q <- function(...) {
sapply(match.call()[-1], deparse)
}
And just to show it works:
> q(a, b, c)
[1] "a" "b" "c"
I have added this function to my Rprofile.site file (see ?Startup
if you are not familiar)
qw <- function(x) unlist(strsplit(x, "[[:space:]]+"))
qw("You can type text here
with linebreaks if you
wish")
# [1] "You" "can" "type" "text"
# [5] "here" "with" "linebreaks" "if"
# [9] "you" "wish"
The popular Hmisc package offers the function Cs()
to do this:
library(Hmisc)
Cs(foo,bar)
[1] "foo" "bar"
which uses a similar strategy to hadley's answer:
Cs
function (...)
{
if (.SV4. || .R.)
as.character(sys.call())[-1]
else {
y <- ((sys.frame())[["..."]])[[1]][-1]
unlist(lapply(y, deparse))
}
}
<environment: namespace:Hmisc>
qw = function(s) unlist(strsplit(s,' '))