Use a variable name with spaces inline in R markdown

How can I include inline R code that refers to a variable name that contains spaces or other unusual characters (actual use-case is Pr(>F))? Backticks are the solution in plain R script, but they don't seem to work when the code is inline in a markdown doc. Here's an example:

```{r}
df <- data.frame(mydata= 1:10, yourdata = 20:29)
names(df) <- c("your data", "my data")

```

The first five values of your data are `r df$`your data`[1:5]`

Which when knitted gives:

Quitting from lines 7-9 (test-main.Rmd) 
Error in base::parse(text = code, srcfile = NULL) : 
  2:0: unexpected end of input
1: df$
   ^
Calls: <Anonymous> ... <Anonymous> -> withVisible -> eval -> parse_only -> <Anonymous>
Execution halted

Note that this is different from showing the backticks. All I want to do is have the code executed when the the doc is knitted. My workaround is to assign the value of the odd-named variable to another object with a simple name in the chunk preceding the inline code. But I'm curious about how to directly call inline these objects with unusual names.

Answers


In this instance can use normal quotes,

 The first five values of your data are `r df$"your data"[1:5]`

or rather

 The first five values of your data are `r df[["your data"]][1:5]`

Need Your Help

Edit mySQL database contents based on username?

php mysql database

So I have a very perfunctory understanding of PHP/mySQL (as in, the extent of my understanding is how much I was able to retain from a few tutorials) and am looking to expand a bit on those tutoria...

Watir-webdriver: I can't click a visible div in an iframe

ruby watir watir-webdriver

I have a facebook app which I'd like to test using Watir.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.