Insert r inline code in abstract with rticles journal template - r

I am using a r-markdown rticles journal template to prepare a manuscript. Almost all rticles templates place the abstract in the YAML header section. I am not able to insert inline r code to the abstract in YAML. I could move the abstract to the text section to insert inline r code. However, the final format would also change. In biomedical field, abstracts often include some numbers from data. What is the best way to add r inline code to the abstract with a rticles journal template? Thanks
Edit: I have just realized that r code for analysis can be placed before the YAML header section. This will solve my problem. Here is a shorten version using Elsevier Journal template:
```{r, echo=FALSE, include=FALSE}
n <- length(mtcars$mpg)
```
---
title: Short Paper
author:
- name: Alice Anonymous
email: alice#example.com
affiliation: Some Institute of Technology
footnote: Corresponding Author
address:
- code: Some Institute of Technology
address: Department, Street, City, State, Zip
abstract: |
There are `r n` observations.
journal: "An awesome journal"
date: "`r Sys.Date()`"
bibliography: mybibfile.bib
csl: elsevier-harvard.csl
output: rticles::elsevier_article
---
However, the journal template in the YAML header is no longer working. Now, I am back to where I started.

Related

Include instructor and course name in the YAML header

In the cover page of the term paper I should include some information as instructor’s name, name of the course, and name of the university.
I added the instructor’s name and the course name and into the YAML header, but they are not shown in the PDF. Moreover, I do not exactly know how to include the name of the PDF, I cannot find a list of tags for the YAML header.
If possible, I would like to solve the problem without installing much software and packages, as it increases the cost of reproducing the code on another computer.
Here the YAML header I used:
---
title: "Cool title"
author: "My Self"
date: "31st February 2023"
instructor: "Dr. Professor"
course: "Econ 101"
output:
pdf_document:
latex_engine: xelatex
editor_options:
chunk_output_type: console
abstract: "This is my abstract, it will be about 100 words"
---
# Introduction #

Cross-referencing in rticles

The bookdown offers great cross-referencing options for equations, figures, tables and sections:
https://bookdown.org/yihui/bookdown/cross-references.html
However, they seems to not work when I set as an output 'rticles::elsevier_article'.
What are the available options for cross-referencing in rticles?
I haven't tried, but there is a possible solution here: https://bookdown.org/yihui/bookdown/a-single-document.html
Particularly, specify in your YAML metadata:
output:
bookdown::pdf_book:
base_format: rticles::elsevier_article
Since I am new using R Markdown I have decided to post this answer as some people may incur in the same mistake. I have tried myself F Rodriguez-Sanchez answer but it did not work. I got the following message:
! LaTeX Error: File `elsarticle.cls' not found.
! Emergency stop.
<read *>
Erro: Failed to compile report.tex. See report.log for more info.
It did not work because I was making a rookie mistake since I was trying to add the suggested answer choosing New Markdownand then choosing Document.
I have then tried to open a New R Markdown choosing From Template and Elsevier Journal Article from rticles package. After that, I have used F Rodriguez-Sanchez suggested answer and it worked!
The final yaml header was:
---
title: Short Paper
author:
- name: Alice Anonymous
email: alice#example.com
affiliation: Some Institute of Technology
footnote: Corresponding Author
- name: Bob Security
email: bob#example.com
affiliation: Another University
address:
- code: Some Institute of Technology
address: Department, Street, City, State, Zip
- code: Another University
address: Department, Street, City, State, Zip
abstract: |
This is the abstract.
It consists of two paragraphs.
journal: "An awesome journal"
date: "`r Sys.Date()`"
bibliography: mybibfile.bib
output:
bookdown::pdf_book:
base_format: rticles::elsevier_article
---
#maycca please make sure to open the RMarkdown by choosing New Files from Template and select the Elsevier Journal version/template. The template(s) will be available after the rticles installation.
This will setup the article "infrastructure" (in particular the respective cls and other files). This also includes a mybibfile.bib example (thus, I would have not needed to comment the biblio out).
If you choose to save this in a sub-folder, make sure that your Rmd file is saved in that sub-folder.
As presented above/below change the output: tag of the YAML to include the bookdown and baseformat rticles::elsevier_article pointer.
Check the use of colons and tabs carefully.
Based on the example above, you can then use the bookdown cross-referencing as shown below. I used
(i) an external (bookdown) figure caption defined before the code chunk using (ref:awesomeplotcaption). This is useful to keep the chunk options short(er).
(ii) a (bookdown) cross-reference to the figure \#ref(fig:awesomeplot). Please note that the \#ref(fig:...) uses the chunk-name to make the pointer work. Thus, make sure your chunk-name comes with standard letters, numbers, and dashes, i.e. no underscore!
Hitting the knit button will do the magic!
---
title: Short Paper
author:
- name: Alice Anonymous
email: alice#example.com
affiliation: Some Institute of Technology
footnote: Corresponding Author
- name: Bob Security
email: bob#example.com
affiliation: Another University
address:
- code: Some Institute of Technology
address: Department, Street, City, State, Zip
- code: Another University
address: Department, Street, City, State, Zip
abstract: |
This is the abstract.
It consists of two paragraphs.
journal: "An awesome journal"
date: "`r Sys.Date()`"
#bibliography: mybibfile.bib
output:
bookdown::pdf_book:
base_format: rticles::elsevier_article
---
# First Heading
Some cool introductory text.
And an even more fascinating plot.
(ref:awesomeplotcaption) A simple demo plot
```{r awesomeplot, fig.cap="(ref:awesomeplotcaption)"}
x <- -5:5
y <- x^2
plot(x,y)
```
More explanatory text.
Using bookdown cross-referencing, have again a closer look at Fig. \#ref(fig:awesomeplot).
This results in the following:
P.S. Focus on the cross-reference and ignore the code-chunk, this could be hidden with echo = FALSE. The figure follows below (in this example, placed via LATEX). I truncated it to keep the figure manageable :)

R markdown / bookdown - how to switch to rticles?

Input data
I prepared an example Rmd file with references to figure, table and equation, setting as an output 'bookdown::pdf_document2'. It compiles without errors to PDF.
I placed it on dropbox:
https://www.dropbox.com/sh/zmu0a4wq95ywssv/AAD-nHlkDiLknLk2NVR4Xup3a?dl=0
Question
Now I wish to set as an output format 'rticles::elsevier_article'
How can I do that?
Issue
When I change output line from:
bookdown::pdf_document2
to
rticles::elsevier_article
I'm receiving an error message.
Even if I remove other parameters from output:
I still receive an error message:
! Undefined control sequence.
Accented characters when input "as is" do not appear to behave well with elsevier_article. See suggestions below.
Bare-bones document
Here is a bare-bones document using rticles::elsevier_article:
---
title: "Sample document"
author:
- name: "Mateusz Kędzior"
affiliation: Some Institute of Technology
email: Mateusz#example.com
footnote: Corresponding Author
- name: Żąćł Źęń
csl: https://www.zotero.org/styles/geoderma
output:
rticles::elsevier_article:
citation_package: natbib
keep_tex: yes
number_sections: yes
toc: no
keywords: keywordA, keywordB
abstract: This is a sample abstract \newline This is the second line of abstract.
---
Hello world.
which renders with no complaints:
Reference with accents
Now, we wish to add a reference with accents. We follow the answer here: https://tex.stackexchange.com/questions/57743/how-to-write-%C3%A4-and-other-umlauts-and-accented-letters-in-bibliography. I imported your bibliography into Zotero, and then exported the item with a "Central European (ISO)" encoding (not UTF-8) to obtain
#article{kedzior_this_2018,
title = {This is sample title only {\k A} {\L }},
volume = {99},
url = {http://megooglethat.com/},
journal = {Some journal},
author = {K{\k e}dzior, Mateusz and {\'Z}{\k e}{\'n}, {\.Z}{\k a}{\'c}{\l }},
year = {2018},
keywords = {keywordC},
pages = {21 -- 31}
}
The R Markdown document now becomes
---
title: "Sample document"
author:
- name: "Mateusz Kędzior"
affiliation: Some Institute of Technology
email: Mateusz#example.com
footnote: Corresponding Author
- name: Żąćł Źęń
csl: https://www.zotero.org/styles/geoderma
output:
rticles::elsevier_article:
citation_package: natbib
keep_tex: yes
number_sections: yes
toc: no
biblio-files: bibliography2.bib
keywords: keywordA, keywordB
abstract: This is a sample abstract \newline This is the second line of abstract.
---
## Citations and references
Let me cite an article: [#kedzior_this_2018]
# References
I then knited this in RStudio, but realised that I had to get the tex output and rebuild it (outside of RStudio) to get the desired output
Other problems
For accented characters in figure captions, encode them accordingly (as with the bibliography). You may find http://w2.syronex.com/jmr/latex-symbols-converter helpful. In addition, to the best of my knowledge bookdown style cross-referencing does not work with rticles. If you have follow-up questions, you may get more helpful answers if you break your question down into smaller chunks.
I've added a bit of updated material to the commenthttps://github.com/rstudio/rticles/issues/92#issuecomment-402784283 where it states (may be updated):
output:
bookdown::pdf_document2:
base_format: rticles::elsevier_article
number_sections: yes
such that the way I've had this work is using pdf_book versus pdf_document2:
output:
bookdown::pdf_book:
base_format: rticles::elsevier_article
number_sections: yes
This allows for figure and table referencing within an rticles document.

Authors in JSS templete for Rticles are superimposed, don't know how to put them in two lines

I am trying to Write a manuscript for the Journal of Statistical Software (JSS) and I have four authors, the problem is that when I knit the manuscript the affiliation of the authors is superimposed. I have seen that in Articles with many authors in JSS they put them in two lines, but I haven't found any way of doing that int the package Rticles, this is an example manuscript with 4 authors
---
author:
- name: Main author
affiliation: University of life and more
address: >
First line
Second line
email: me#university.edu
url: http://rstudio.com
- name: second author
affiliation: University of life and more
- name: Third Author
affiliation: University of life and more
- name: Fourth Author
affiliation: University of life and more
title:
formatted: "super interesting r package called \\pkg{TheSuperPackage}"
short: "\\pkg{TheSuperPackage}: This is exiting"
abstract: >
We present a package that will solve your life
keywords:
# at least one keyword must be supplied
formatted: [ "\\pkg{TheSuperPackage}", Life, "\\proglang{R}"]
plain: [keywords, not capitalized, life]
preamble: >
\usepackage{amsmath}
biblio-style: jss
output:
rticles::jss_article:
fig_caption: true
citation_package: natbib
bibliography: Derek.bib
---
```{r, echo=FALSE, warning=FALSE, message=FALSE}
library(rticles)
library(rmarkdown)
library(yaml)
```
```{r, echo=FALSE, warning=FALSE}
library(knitr)
opts_chunk$set(prompt=TRUE)
options(replace.assign=TRUE, width=90, prompt="R> ")
```
# Introduction
This template demonstrates some of the basic latex you'll need to know to create a JSS article.
Any help would be greatly appreciated

multiple authors and subtitles in Rmarkdown yaml

I'm trying to follow this pandoc example to add multiple authors to an Rmarkdown file in the yaml metadata block. The pdf will generate in RStudio (Version 0.98.932), but there is no author information.
---
title: 'This is the title: it contains a colon'
author:
- name: Author One
affiliation: University of Somewhere
- name: Author Two
affiliation: University of Nowhere
date: "`r format(Sys.time(), '%d %B %Y')`"
tags: [nothing, nothingness]
abstract: |
This is the abstract.
It consists of two paragraphs.
output: pdf_document
---
I'd also like to customize the heading a bit more and add a subtitle. Possible?
I just found out that it is possible to add subtitles to R markdown PDF output. I am using R 3.2.2 and RStudio 0.99.473 in Ubuntu 14.04.
---
title: 'This is the title: it contains a colon'
subtitle: 'This is the subtitle'
output: pdf_document
---
The default latex template in rmarkdown does not support author affiliations or subtitles. It does support multiple authors however, the correct yaml syntax is
---
title: 'This is the title: it contains a colon'
author:
- Author One
- Author Two
date: "`r format(Sys.time(), '%d %B %Y')`"
tags: [nothing, nothingness]
abstract: |
This is the abstract.
It consists of two paragraphs.
output:
pdf_document:
template: NULL
---
If you want to customize your header, the best approach is to modify the latex template, found here to suit your needs. Then copy it to your local directory and pass it to the header in the template field.
As explained in the main answer, the default R Markdown template does not support author affiliations. While users can edit the template file to add their own custom YAML fields, there are easier some workarounds you can use for PDF or HTML outputs.
HTML Outputs
You can use the recently released radix template. First you must install the package:
install.packages("radix")
Once installed, you must set the
---
title: "Radix for R Markdown"
description: |
Scientific and technical writing, native to the web
date: May 4, 2018
author:
- name: "JJ Allaire"
url: https://github.com/jjallaire
affiliation: RStudio
affiliation_url: https://www.rstudio.com
- name: "Rich Iannone"
url: https://github.com/rich-iannone
affiliation: RStudio
affiliation_url: https://www.rstudio.com
output: radix::radix_article
---
Your content
PDF Outputs
You can use premade templates, and there are some good examples within the rticles package. First we must install the package:
install.packages("rticles")
Once Installed, you can use one of the templates, such as the Journal of Statistical Software:
---
author:
- name: FirstName LastName
affiliation: University/Company
address: >
First line
Second line
email: \email{name#company.com}
url: http://rstudio.com
- name: Second Author
affiliation: Affiliation
title:
formatted: "A Capitalized Title: Something about a Package \\pkg{foo}"
# If you use tex in the formatted title, also supply version without
plain: "A Capitalized Title: Something about a Package foo"
# For running headers, if needed
short: "\\pkg{foo}: A Capitalized Title"
abstract: >
The abstract of the article.
keywords:
# at least one keyword must be supplied
formatted: [keywords, not capitalized, "\\proglang{Java}"]
plain: [keywords, not capitalized, Java]
preamble: >
\usepackage{amsmath}
output: rticles::jss_article
---
If you render a pdf, LaTex use authors' footnote for affiliations (i.e. converting numbering in symbles). Try
---
title: 'This is the title: it contains a colon'
subtitle: 'This is the subtitle'
author:
- Author One^[University of Somewhere]
- Author Two^[University of Nowhere]
date: "`r format(Sys.time(), '%d %B %Y')`"
tags: [nothing, nothingness]
abstract: |
This is the abstract.
It consists of two paragraphs.
output: pdf_document
---
I've found a solution to your subtitle part of the question here: https://stackoverflow.com/a/41444545/14027216
You can add subtitle by adding subtitle: to your code and multiple subtitles can be added as follow:
---
title: 'This is the title: it contains a colon'
subtitle: |
| 'subtitle 1'
| 'subtitle 2'
author:
- name: Author One
affiliation: University of Somewhere
- name: Author Two
affiliation: University of Nowhere
date: "`r format(Sys.time(), '%d %B %Y')`"
tags: [nothing, nothingness]
abstract: |
This is the abstract.
It consists of two paragraphs.
output: pdf_document
---
You can add more than two subtitles, but I don't know the maximum amount. Each subtitle will be displayed in new line.
I've also had this problem. Following the suggestion from #tmpname12345 I modified the latex template (default.tex) and the html template (default.html) to render subtitles. This pull request is on github rstudio/rmarkdown if you want the code quickly, and looks like it will be standard in rmarkdown next time they push to CRAN.
Add to the answer by Ze Grisi, i just discovered adding html heading tags into the yaml works to adjust the font in the title and subtitle. Note the quotation marks are no longer needed.
---
title: 'This is the title: it contains a colon'
subtitle: <h1>This is the subtitle</h1>
output: pdf_document
---
For a more dramatic effect add an underline to the subtitle
---
title: 'This is the title: it contains a colon'
subtitle: <h1><u>This is the subtitle</u></h1>
output: pdf_document
---
Using a solution for latex here enter link description here by #greg. I put the latex code into rmarkdown yaml header with some changes and it does the job.
---
title: 'Some Title'
author: Author One$^1$ \and
Author Two$^2$ \and
Author Three$^3$
date: $^1$Organization 1 \newline
$^2$Organization 2 \newline
$^3$Organization 3
\newline
\newline
\today
output:
---
The trick is to put the affiliations into date tag.

Resources