R有像Perl的qw()这样的引用类运算符吗?
任何人都知道,如果R有像Perl的qw()这样的引用运算符来生成字符向量? 
不,但你可以自己写:
 q <- function(...) { sapply(match.call()[-1], deparse) } 
只是为了显示它的作品:
 > q(a, b, c) [1] "a" "b" "c" 
我已经将这个函数添加到我的Rprofile.site文件中(如果你不熟悉,
 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" 
 stream行的Hmisc包提供了Cs()函数来完成这个工作: 
 library(Hmisc) Cs(foo,bar) [1] "foo" "bar" 
对哈德利的回答采用了类似的策略:
 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,' ')) 
更简单:
 qw <- function(...){ as.character(substitute(list(...)))[-1] }