[R] paste() turns list element character vector into deparsed expression. Why?

Boris Steipe bor|@@@te|pe @end|ng |rom utoronto@c@
Mon Nov 9 12:38:12 CET 2020


I was just surprised by very un-intuitive behaviour of paste(), which appears to collapse a one-column data frame or one-element list into a deparsed expression, rather than producing the expected string. Can someone kindly explain what's going on here?


reprex:
=======

list(s = c("xyz", "uvw"))
#     s
# 1 xyz
# 2 uvw

paste(list(s = c("xyz", "uvw")), collapse = "")
# [1] "c(\"xyz\", \"uvw\")"   # This is unexpected!

I would have expected:
# [1] "xyzuvw"
 
... which I do get with e.g.
paste(list(s = c("xyz", "uvw"))$s, collapse = "")

But what logic is there in returning a deparsed expression?



Thanks!
Boris


More information about the R-help mailing list