I have scraped text and have placed it into a tibble with one character variable "value" and one observation of this variable ""this is a character variable".
I want to print the contents of character_variable$value as text in the output of an Rmarkdown document that is knitted to a Word document.
However, the code snippets used in this and similar examples don't appear to be applicable to character variables.
What I would like to see in the Word document output:
This is the text I have scraped: this is a character variable.
# Text scraped from somewhere and placed into the variable "value" in the tibble "character_variable"
character_variable <- ("this is a character variable")
character_variable <- as_tibble(character_variable)
character_variable
# value
# <chr>
# this is a character variable
# 1 row
#code snippet that appears to be applicable to numerical variables but not character variables:
text 'This is the text I have scraped: `r character_variable`.'
Does anyone have any experience with this or insight in how to accomplish it?
My final desired output is this sentence: This is the text I have scraped: this is a character variable.
I want this output in a Word document knitted frrom the Rmarkdown script.
The section "this is a character variable" is the contents of the variable "value" in the tibble, character_value.
This snippet of code returns the error listed below the snippet.
# Text scraped from somewhere and placed into the variable "character_variable"
character_variable <- ("this is a character variable")
character_variable <- as_tibble(character_variable)
text 'This is the text I have scraped: `r character_variable$value`.'
Error: unexpected string constant in "text 'This is the text I have scraped: r character_variable$value.'"
Your problem is that you are putting text inside the r code chunk, just take it out.
---
title: "Untitled"
output: word_document
---
```{r}
library(tibble)
# Text scraped from somewhere and placed into the variable "character_variable"
character_variable <- "this is a character variable"
character_variable <- as_tibble(character_variable)
```
This is the text I have scraped: `r character_variable$value`.