0

I'm working on a dataset in which I need to deal with some quotation marks. The Advanced R book has exactly what I need - it is here. However, when I run the example that's given, I get an error that makes no sense to me.

From that webpage: "Imagine you’re creating a lot of strings by joining together words"

paste("Good", "morning", "Hadley")

This produces the expected result (i.e., the phrase "Good morning Hadley" without quotes). "However, I don't want to deal with the quotation marks. Again, from the website: You are sick and tired of writing all those quotes, and instead you just want to use bare words. To that end, you’ve written the following function"

# Just in case
library(tidyverse)

cement <- function(...) {
  args <- ensyms(...)
  paste(purrr::map(args, as_string), collapse = " ")
}

cement(Good, morning, Hadley)

In the text, this should produce the same result (i.e., Good morning Hadley). I'm sure everyone else gets that. When I run this, I get the error:

Error in as_mapper(.f, ...) : object 'as_string' not found

I have no idea why this would happen. My version of R (4.1.3), RStudio (2022.02.0, Built 443), and purrr (0.3.4) are all up to date; I'm running on a MacBook Pro (OS 12.12.1). Thoughts?

Karl Wolfschtagg
  • 425
  • 2
  • 10
  • 3
    `as_string` is from the rlang package. You would need to include `library(rlang)` or use `rlang::as_string`. If you scroll a couple paragraphs up, you'll see Hadley loads `library(rlang)` in the "Prerequisites" section. – zephryl Mar 31 '22 at 15:00
  • Wow. I should go back to bed. Thanks for that! – Karl Wolfschtagg Mar 31 '22 at 15:08

0 Answers0