-4
a <- "t"
bquote(data.frame(.(a) = 1:10)
Error: unexpected '=' in "bquote(data.frame(.(a) ="

a needs to be dynamic. How can this be accomplished?

1 Answers1

2

You cannot use bquote for this. The easiest way to solve this is just to use setNames()

a <- "t"
setNames(data.frame(1:10), a))

Alternative you could build the data.frame call and then use do.call but you still have to set the parameter name with setNames()

do.call("data.frame", setNames(list(1:10), a))

But if you are using tidyverse packages, you can dynamically set names in a tibble call using :=

tibble(!!a := 1:10)
MrFlick
  • 195,160
  • 17
  • 277
  • 295