qwa - A quick way to characterize an argument list

Having grown up and aged in linux, c, bash, and perl households, I felt that R lacked constructs to allow concise ways of getting down to business.

I became tired of typing quote-comma-quote and missed perl's qw function that compactly transforms its argument of strings separated by white space into an array.

I came up with this alternative:

qwa<-function(...) as.character(match.call(expand.dots=TRUE))[-1]  # discard the "qwa" function call

# a simple example
# [1] "a" "b" "c"

# including quoted strings
qwa(This,That,"some other thing")
# [1] "This"             "That"             "some other thing"

# and more  complex expressions
qwa(1,2,3,c(1,2,3),function(...) "z")
# [1] "1"                   "2"                   "3"                
# [4] "c(1, 2, 3)"          "function(...) \"z\""

I suppose it's possible to recursively do.call down the expressions to return a tree/list, but I called it a day.

J. Bullock's qw function also divides a string argument by whitespace to return a character vector.

Please let me know if there's a better way to go about this. Appreciate feedback/comments

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.