0

How does that code works? The main goal was to asign a string to a variable and then make a dataframe which the first column is the string. So in this case you could do that:

# column1 <- "Student Name"
df1 <- tibble(`Student Name` = rep('fill', 3))

But that's not the challenge.

If you try this:

column1 <- "Student Name"
df1 <- tibble(`column1` = rep('fill', 3))

It doesn't work as well.

So, browsing in the internet i found this solution, and it works

column1 <- "Student Name"
df1 <- tibble({{column1}} := rep('fill', 3))

But still, i don't know how this code works, i know that he uses curly curly operator, which i've never seen before, and this ':=' operator as well. Can someone explain how does that work? I've searched for this curlycurly operator but was a little bit hard to comprehend.

Jon Spring
  • 55,165
  • 4
  • 35
  • 53
chunli
  • 3
  • 1
  • 3
    See https://dplyr.tidyverse.org/articles/programming.html#indirection – Jon Spring Jul 20 '23 at 00:06
  • 1
    Also relevant: https://stackoverflow.com/questions/61295654/dplyr-non-standard-evaluation-and-walrus-operator-and-curly-curly and https://stackoverflow.com/questions/62791997/what-is-the-embracing-operator. Do you have a question beyond what those answers covered? – Jon Spring Jul 20 '23 at 00:07

0 Answers0