Error with loading png in Rmd file - r

i am trying (invane) to load a png file in my Rmd file.
I save both the Rmd and the png in the same folder on my main drive (I tested i can read/write files in there with R).
When i run the following code
---
title: "Determinants of profitability"
author: "Daniele Frison"
date: "26 November 2015"
output:
html_document:
fig_height: 10
fig_width: 10
---
```{r}
![aaa](prof_vs_costs.png)
```
I get inexorably this error message:
|................................ | 50%
ordinary text without R code
|.................................................................| 100%
label: unnamed-chunk-1
processing file: test.Rmd
Quitting from lines 13-16 (test.Rmd)
Error in parse(text = x, srcfile = src) : <text>:2:2: unexpected '['
1:
2: ![
^
Calls: <Anonymous> ... <Anonymous> -> parse_all -> parse_all.character -> parse
Execution halted
I can't find what is the problem with this parse.
Thanks in advance for your kind help

Related

YAML parser error when rendering Quarto document

I was trying to re-render a Quarto document after adding some more code. The code previously rendered fine.
However, this time the render failed, with this error:
Error in yaml::yaml.load(meta, handlers = list(expr = parse_only)) :
Parser error: while parsing a block mapping at line 1, column 1 did not find expected key at line 2, column 27
Calls: .main ... FUN -> parse_block -> partition_chunk -> <Anonymous>
Execution halted
I thought this was referring to the YAML bit at the top, but I hadn't made any changes to that, and the document previously rendered fine. I simplified the YAML to the simplest case, but the error persisted.
---
title: "Test"
format: html
---
```{r}
#| label: tbl-exibble
#| tbl-cap: "Exibble Bla Bla")
gt::gt(exibble)
```
This was caused by a typo - I'm posting this and answering it here because I think the error message is not particularly helpful and it might mislead other people
The bug lies in the table caption chunk option, not in the YAML block at the start.
I had an extra ) at the end of the line; this fixed it:
---
title: "Test"
format: html
---
```{r}
#| label: tbl-exibble
#| tbl-cap: "Exibble Bla Bla"
gt::gt(exibble)
So if you get YAML parser errors similar to mine, please check your YAML; not only in the top part of the Quarto document, but also in your chunk options.
You do not even need ", e.g.
---
title: "Test"
format: html
---
```{r}
#| label: tbl-exibble
#| tbl-cap: Exibble Bla Bla)))))
gt::gt(mtcars)
```
inline code
---
title: "Test"
format: html
---
```{r}
#| label: tbl-exibble
#| tbl-cap: !expr paste0("mtcars")
gt::gt(mtcars)
```

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.

R Markdown error

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

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