Questions tagged [knitr]
knitr is an R package for dynamic report generation based on the concept of literate programming.
367
questions
0
votes
0
answers
16
views
Add greek letter in column header kable and add %-sign in rowname
I had some questions when making a table using kable in Rmarkdown. My output has to be a pdf document, so my header is the following:
output:
pdf_document:
latex_engine: xelatex
...
0
votes
0
answers
23
views
Wrong output format while running knitr script in TeXworks
I wanted to use knitr with my TeXworks install and am noticing a weird issue. I followed the tutorial as described by Yihui here which worked fine. Now suppose my filename is untitled-12.tex and it ...
1
vote
1
answer
35
views
Signature image and date on same line hfill not working and wrapping into new line
I am trying to prefill the signature and date on a document as follows. Everything looks right, except the date wraps into new line instead of sitting on the same line as the signature image.
What am ...
0
votes
0
answers
31
views
knitr + tikzDevice + apa7 class + input in premable produces "unable to calculate metrics" error
When using the apa7 class and input{} in the preamble, knitr chunks with the option dev='tikz' will no longer produce images and instead print out an error message.
Here is a MWE:
\documentclass[man]{...
1
vote
1
answer
101
views
knitr - function that works both in \Sexpr and in code-chunks
I try to learn knitr.
knitr lets you nest snippets of "inline-code" written in the language R between \Sexpr{...}.
knitr lets you nest "code-chunks" written in the language R ...
1
vote
0
answers
447
views
How to use Latex with knitr on online editor
I am having troubles with R code. I want to write my bachelor's thesis and I do it in R.
Since I am using R, I use knitr package & format and I also use Overleaf as editor + .tex (LaTeX) code, not ...
0
votes
1
answer
301
views
R - Escaping a character from the BEST package for tikzDevice
I try to modify some plot output from the R BEST package with the help of the package tikzDevice. However, apparently tikzDevice can not proceed due to a parameter with a percent sign ("% HDI&...
0
votes
2
answers
494
views
Error in the code after loading a library in an R code
I have been writing a code in RStudio and using TinyTex to compile my pdf. I wrote the following code in an RSweave file in RStudio:
\documentclass[12 pt]{article}
\usepackage[utf8]{inputenc}
\...
0
votes
1
answer
470
views
How can I mark a portion of R code to be bold in Latex output?
Rmarkdown YAML
output:
pdf_document:
latex_engine: xelatex
classoption: x11names
documentclass: article
header-includes:
- \PassOptionsToPackage{x11names}{xcolor}
- \usepackage{eso-pic,...
0
votes
1
answer
68
views
How do I adjust these texts dynamically depending on length of name?
The following code
\documentclass{article}
\usepackage{eso-pic,graphicx}
\usepackage[absolute,overlay]{textpos}
\usepackage{fontspec}
\setmainfont{Segoe UI Symbol}
\usepackage[top=2cm, bottom=2cm, ...
1
vote
0
answers
22
views
How do I assign these variables from Rmarkdown? [duplicate]
I have variables that are going to be dynamic in this document. How do I assign theme from Rmarkdown.
Below is how my .tex file looks like
So for example $District_Name$ is a dynamic variable.
I want ...
2
votes
1
answer
307
views
Change the style of chapters (sections) of the .pdf document from rstudio with knitr package LATEX "titlesec"
I try to style the chapters (sections) of an article document (documentclass: article) using the latex titlesec package, but I don't get any results, I mean that when I configure the document there is ...
1
vote
0
answers
77
views
How can I get R and Tikz to cooperate in a loop?
I'm using knitr and compiling my .Rnw file in Rstudio. Here's a MWE illustrating my issue. I want the code below to output "1, 2, 3" but instead it gives me "1, 1, 1".
%%%%%%%%%%%%%...
1
vote
1
answer
337
views
How to replace all : with * or x in an ANOVA table?
I am using bookdown::pdf_document2. Some journals require all the interaction terms to be formatted as Term A * Term B or Term A x Term B, not Term A : Term B as default in the R's ANOVA table.
...
1
vote
0
answers
1k
views
RStudio, pdflatex fails to knit to pdf and crashes
I'm trying to compile a simple Rnw file in RStudio using knitr's "compile pdf" functionality. But it gives me an error.
This is what I have in Vorlage.Rnw:
\begin{document}
Hello World
\...
0
votes
0
answers
99
views
How to set the same length between paragraphs when there is a verbatim box?
What I want is to have 1em of distance between the paragraph and the verbatim box and 1em after the verbatim box and the next paragraph. I am using Rstudio with Knitr and PDFLatex. This is what I have ...
6
votes
1
answer
539
views
What could be causing TeXLive packages to update without explicit user intervention?
Up until now I was under the impression that TeXLive's packages only updated when you invoked tlmgr update ....
But today I noticed, for the first time, that some other process is definitely updating ...
0
votes
1
answer
375
views
\textwidth is not recognized, causes illegal unit error
I switched computers, reinstalled R, and am now getting an "Illegal unit of measure" error when I run the following code. I've narrowed it down to the "\textwidth" portion - when I ...
1
vote
1
answer
323
views
How to pass a variable from Rmd file to a latex file
I have two file 1. index.rmd file and the other is 2.Preamble.tex file
I want to delclare a variable in index.rmd i.e.
a <- 'Start and end with single quote'
I want to pass the above variable in ...
1
vote
0
answers
162
views
Sweave compiles empty table of contents
I have a .tex document which I want to compile using Sweave. I provide its and the .cls file's contents below. Everything works fine, except for the fact that the table of contents is empty. I am ...
2
votes
1
answer
229
views
texshop knitr -> XeLaTeX engine
In TeXShop, my current knitr engine is
#!/bin/bash
export PATH=$PATH:/usr/texbin:/usr/local/bin
Rscript -e "library(knitr); knit('$1')"
latexmk -pdf "${1%.*}"
My current XeLaTeX ...
2
votes
1
answer
91
views
SyncTeX inverse search with WinEdt and Rnw files
I am using WinEdt 9.1 with RManager and pdflatex to knit PDF files from Rnw files. The process generally works well. But I cannot use "inverse search" from my PDF documents to my Rnw files. ...
1
vote
2
answers
1k
views
R markdown / Plotly R with LaTeX unable to generate plot and get error on a file name with hyphen
I am using LaTeX for some formatting, and trying to generate a PDF file with a plotly R plot as a png. The following piece of code gives me an error as show below. It seems like a problem with the ...
2
votes
1
answer
77
views
Knitr: storing variables for later use
I'm relatively new to Knitr. I want to run a function just once, so that next time I don't have to evaluate it, because it would yield a different result. My MWE:
First time:
\documentclass{article}
\...
1
vote
1
answer
345
views
Knitr + Latex can't write foreign characters (æ ø å) inside the R code boxes
I cannot make Latex write æ ø and å when using Knitr, despite trying various solutions from other posts. I'm on a windows machine with windows 10 installed.
Here is a minimal example:
\documentclass{...
1
vote
1
answer
798
views
Rmarkdown, plot title font as latin modern
I have an knitr document with single plot. I want to use the original fonts of R in the plot except the axis labels which should come from latin modern. I can use latin modern for all the fonts in the ...
1
vote
2
answers
4k
views
How to keep a table on the same page?
I have a report with many summary tables of regression output and converted them into tables using pander in the Rmarkdown document. Even though all tables are less than one page, they sometimes break ...
3
votes
1
answer
179
views
Knitr adding part of preamble twice
I am working on my dissertation and received a .tex document with a lot of the formatting requirements included. I have started adding items, importing additional .Rnw files for different chapters. ...
1
vote
1
answer
128
views
How to prevent of removing spaces from string by Sexpr?
Here is a string variable.
a <- 'This is a sample sentence'
If I want to print in inline text mode for PDF, I can write it this way:
$\Sexpr{a}$
But, I am getting the output like this way:
...
0
votes
0
answers
234
views
How to automatically escape special characters in Sexpr in knitr?
I have the following code in a knitr doc:
\title{Metrics for \Sexpr{display_name}}
where display_name was set by some previous code.
If that name has special characters (e.g., Mary & Sue ...
1
vote
1
answer
167
views
Spaces in data.frame in R Sweave
I'm making a table in R Sweave using a data frame, but I don't know how to create spaces between the titles, they come out is separated by points. Is there a command that solves this?
with the ...
1
vote
1
answer
204
views
Error about double wide hat
I am doing my homework and some column head looks weird due to error.
What is the problem here?
5
votes
1
answer
463
views
Getting latexmk to work with both .tex and .Rnw files
System information
Mint 19.2
latexmk 4.41
pdfTeX 3.14159265-2.6-1.40.18 (TeX Live 2017/Debian)
Goal
I am trying to set up my .latexmkrc configuration so it detects whether the file that is passed is ...
1
vote
1
answer
2k
views
An R function for writing a tex file to folder
Is there a function in R that will allow me to write a latex code for tables with a .tex name file to a folder. Or simply just like we have a write.csv function that can write a table of dataset to a ...
1
vote
1
answer
60
views
How compile Knitr in TeXnicCenter?
some of you have tried using TeXnicCenter to compile Knitr, well I would use TexStudio but it is heavy again.
I appreciate your help
error
'Rscript.exe no such file or directory'
0
votes
0
answers
241
views
Issue with fig=TRUE in Sweave RStudio
I do not receive plots using the fig=TRUE in the chunks. Rather i receive an 'undefined control sequence' error.
Consider a simple code
\documentclass{article}
\usepackage{graphicx}
\begin{document}
...
4
votes
1
answer
2k
views
R Markdown/pandoc: Change how code blocks are converted to LaTeX
I use rmarkdown to generate a pdf file (which uses pandoc, which in turn uses pdflatex). By enabling keep_tex option, I noticed that code blocks without language type always become verbatim, e.g.:
```...
2
votes
2
answers
4k
views
How can I have a latex type expression as a column name in R?
I am working on many kables using the kableExtra package. Say you have a dataframe,df, that is 5 rows and 5 columns.
in R you can do names(df)=c("A","B","C","D","E") for example.
Once you have the ...
2
votes
2
answers
659
views
Basic R code yields errors of "unclosed $" in knitr
I cannot use R code in Overleaf Knitr, since any basic code which includes $ yields error of unclosed $.
Even the sample file of knitr in Overleaf itself causes LaTeX error: https://www.overleaf.com/...
0
votes
0
answers
734
views
The code works in R, but not while compiling it in LaTeX
I am trying to compile a code in LaTeX (the code is prepared by knitr in R). In RStudio everything seems to be OK:
Writing to file Trial.tex
Processing code chunks with options ...
1 : keep.source ...
2
votes
0
answers
2k
views
Cannot install packages in the Knitr environment Overleaf
I am trying to write my R code directly in my Overleaf document using knitR. However, this message pops up when I run the following code:
<>=
# Install relevant packages
install.packages('...
1
vote
1
answer
1k
views
Is there a latex package for working with Rtex files locally
Working with Overleaf using .Rtex files and I love it. However, I just discovered that Overleaf does not support a lot of the R packages (e.g., tidyverse, sqldf) and does not work with large data sets....
2
votes
1
answer
2k
views
Embedding R (kable) results in LaTeX
Apology at first if this question has been asked or the sample is not reproducible. I'm totally new to LaTex and happy to take any advice.
I am working on my thesis on a .tex LaTex template given by ...
2
votes
1
answer
194
views
Manual bibliography in knitR with \bibitem{} works but cannot use \cite{} with it
I am trying to use a manual/embedded bibiography in a knitR/LaTeX document (long story short but for various reasons I don't want to be using a seperate .bib file because this script will be used many ...
2
votes
2
answers
1k
views
How to use \sexpr{} with variable that has "_" in it (i.e. avoid "math mode" error)
I am using knitr in R to write up a document in LaTex. Below a certain of code, I would like to refer to a variable I used in R.
<<chunk>>
var <- "ENSEMBL_MART_ENSEMBL"
@
In this ...
2
votes
1
answer
174
views
Class tufte-book and R listings code box width problem
When I run the following MWE:
\documentclass{tufte-book}
\usepackage{Sweavel}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage{soul}
%%%%%%%%%%
% R example
%%%%%%%%%%
\newtheoremstyle{rex}{}{...
1
vote
0
answers
492
views
read_chunk doesn't work [closed]
I tried the code suggested previously which should work
execute R code in latex file imported from separate R file
but I can't see the external-code from R.
Here's my script
\documentclass[12pt,...
1
vote
1
answer
758
views
Syntax highlighting not working properly
I'm using TeXstudio and for a while now, every time I write in math mode using $...$ or \[...\], it highlights most of the commands as if they were syntax errors although it compiles just fine. For ...
1
vote
0
answers
450
views
Run code chunks in subfiles
My document consists of several subfiles that are imported into my main. However, i would like to run code chunks with R output in each subfile before the document is stitched together by main.tex. I'...
2
votes
1
answer
716
views
How to cite german book titles properly (upper case) with csl and rmarkdown?
I am using RMarkdown in RStudio and want to cite several sources using csl, specifically I use the style "elsevier-with-titles.csl". I want to cite a german reference, so title must have upper case ...