R Markdown error - r

I am trying to create an R markdown file but when I do I get the following error:
Line 2:
Error in .Call(C_str Sub_replacement, str, from, to, NULL, value) :
Incorrect number of arguments (5), expecting 6 for 'C_str Sub Replacement'
Calls: <Anonymous> ... indir -> inline exec -> <Anonymous> -> str_sub<- -> .Call
I have tried searching the internet and can not find an answer to this specific error. I am running R-3.3.0 and using R Studio.
I have updated the packages - knitr, markdown and yaml.
The following is my set up:
---
title: "Setting up a DQASS PC"
author: "DKMillington"
date: "`r format(Sys.Date(), '%d/%m/%Y')`"
header-includes:
- \usepackage{amsmath}
output:
rmarkdown::html_vignette:
css: mystyle.css
toc: true
number_sections: true
---
```{r, echo = FALSE, message = FALSE}
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
library(dqass)
```
Thank you for your time in advance.
Dale

Related

R Markdown Unable to knit to PDF - Error in tmlr

My markdown file won't knit to PDF and returns the following error:
Unmatched ( in regex; marked by <-- HERE in m//( <-- HERE .sty/ at
/usr/local/bin/tlmgr line 1778. Error in grep(paste0("/", x[j], "$"),
l) : invalid regular expression '/(.sty$', reason 'Missing ')''
Calls: ... system2_quiet -> on_error -> parse_packages ->
grep
I am on a Mac and everything was working yesterday, and then I installed tinytex (I may have installed it twice) and now I cannot knit to PDF. Has anyone seen this error before? Or worked with tmlr?
I have tried uninstalling tinytex and reinstalling Rstudio.
If it helps, my YAML heading is:
---
title: \vspace{2in}"**Borrower Feedback Analysis**"
date: "`r Sys.Date()`"
#output: html_document
output:
pdf_document:
latex_engine : xelatex
toc: true
toc_depth: 1
header-includes:
- \usepackage(tinytex)
- \usepackage{sectsty}
- \usepackage{xcolor}
- \definecolor{blendHeaderBlue}{HTML}{00146b}
- \definecolor{blendParahraphBlue}{HTML}{4a578f}
- \sectionfont{\color{blendHeaderBlue}}
- \subsectionfont{\color{blue}}
- \paragraphfont{\color{blue}}
geometry: margin= .9in
fontsize: 10pt
---

How to use lua-filter with bookdown gitbook output?

I have an example bookdown project with gitbook output
index.Rmd:
---
title: "An Example Project"
author: "Coderoo"
output:
bookdown::gitbook: default
pandoc_args: ["--lua-filter=hello.lua"]
documentclass: book
---
Some text {{helloworld}}
hello.lua is taken straight from the pandoc lua-filter doc:
return {
{
Str = function (elem)
if elem.text == "{{helloworld}}" then
return pandoc.Emph {pandoc.Str "Hello, World"}
else
return elem
end
end,
}
}
But when I try to build the book:
Rscript -e "bookdown::render_book('index.Rmd','bookdown::gitbook')"
I get this error:
Error in yaml::yaml.load(..., eval.expr = TRUE) :
Scanner error: mapping values are not allowed in this context at line 5, column 16
Calls: <Anonymous> ... parse_yaml_front_matter -> yaml_load -> <Anonymous> -> .Call
Please delete _main.Rmd after you finish debugging the error.
Execution halted
If I replace bookdown::gitbook default in the YAML metadata with html_document then everything works fine.
Crossposted here as well: https://community.rstudio.com/t/how-to-use-lua-filter-with-gitbook-output/48256
EDIT: Answered in the rstudio forum.

LuaLaTex and _output.yml configuration - Error in base format()

I am learning how to use bookdown package and right now I am practicing with Yihui Xie minimal example. In my test I want a gitbook and a pdf output.
What I would like to do is to specifying some options for pdf output with LuaLaTeX engine. So if I do something like that :
bookdown::gitbook:
css: style.css
config:
toc:
before: |
<li>A Minimal Book Example</li>
after: |
<li>Published with bookdown</li>
download: ["pdf", "epub"]
bookdown::pdf_book:
includes:
in_header: preamble.tex
latex_engine: lualatex
fontsize: 12pt
citation_package: natbib
keep_tex: yes
bookdown::epub_book: default
I have this error when I try to build the book :
Error in base_format(toc = toc, number_sections = number_sections, fig_caption = fig_caption, :
unused argument (fontsize = "12pt")
Calls: <Anonymous> ... <Anonymous> -> create_output_format -> do.call -> <Anonymous>
Execution stoped
Exited with status 1.
If I put fontsize: 12pt in the YAML header of the index.Rmd, I don't have this error. If I use bookdown::pdf_document2: I don't have this error either.
I really don't know what I am missing here... Should I place LaTeX configuration options only in the YAML header of my index.Rmdfile ?

Can't use PLOS rticles template with bookdown

Following this post, I'm trying to put #YihuiXie 's answer in practice with the PLOS template of rticles but it doesn't work. Any help would be very appreciated!
Below in a minimal example:
---
title: Title of submission to PLOS journal
author:
- name: Me
affiliation: Here
# output: rticles::plos_article
output:
bookdown::pdf_document2:
base_format: rticles::plos_article
---
# Introduction
Some text \#ref(fig:fig1)
# References {#references .unnumbered}
The error message reads
Error in pdf_book(..., base_format = rmarkdown::pdf_document) : formal argument "base_format" matched by multiple actual arguments
Calls: <Anonymous> -> create_output_format -> do.call -> <Anonymous>
Execution halted
You cannot change the base_format for bookdown::pdf_document2. You can do so for bookdown::pdf_book, though:
---
title: Title of submission to PLOS journal
author:
- name: Me
affiliation: Here
#output: rticles::plos_article
output:
bookdown::pdf_book:
base_format: rticles::plos_article
---
# Introduction
Some text \#ref(fig:fig1)
# References {#references .unnumbered}
Note to other readers: Make sure that .../rticles/rmarkdown/templates/plos_article/skeleton/PLOS-submission.eps is present in that directory.

Accessing data generated by an R script with r markdown and knitr

I am new to R markdown and knitr and haven't found the answer to this question:
I have R scripts where I've written functions and have assigned data to position 1 (.GlobalEnv). How do I access my data and run my functions within R markdown and generate the .html file with knitr?
Here's a trivial example. In a script file I generate:
some.x.data<-1:10
some.y.data<-1:10
toy.fn<-function(){
tot<-some.x.data + some.y.data
tot
}
toy.fn() works in the script file.
My R markdown file contains:
---
title: "trivial test"
author: "me"
date: "July 9, 2015"
output: html_document
---
```{r}
plot(some.x.data, some.y.data)
toy.fn()
```
When I click knit HTML, I get the following error:
Error in plot(some.x.data, some.y.data) : object 'some.x.data' not found
Calls: ... withCallingHandlers -> withVisible -> eval -> eval -> plot
Thanks
RStudio opens a new R session to knit() your Rmd file, so the objects in .GlobalEnv will not be available to that session (they are two separate sessions), so when you are knitring HTML there is not way to know what some.x.data, some.y.data and toy.fn is.
Either you need to recreate them in your Rmd file. If you don't want any output just do:
```{r, echo = FALSE, message = FALSE}
some.x.data<-1:10
some.y.data<-1:10
toy.fn<-function(){
tot<-some.x.data + some.y.data
tot
}
```
Full Rmd:
---
title: "trivial test"
author: "me"
date: "July 9, 2015"
output: html_document
---
```{r, echo = FALSE, message = FALSE}
some.x.data<-1:10
some.y.data<-1:10
toy.fn<-function(){
tot<-some.x.data + some.y.data
tot
}
```
```{r}
plot(some.x.data, some.y.data)
toy.fn()
```
Or
knit manually by yourself: library(knitr); knit('your_file.Rmd')

Resources