Skip to main content

Questions tagged [knitr]

knitr is an R package for dynamic report generation based on the concept of literate programming.

Filter by
Sorted by
Tagged with
2 votes
1 answer
36 views

Set global options for all R code chunks and plots throughout LaTeX document

Making a couple of R plots in my LaTeX document on Overleaf. Every R plot is being placed inside of a figure environment: \begin{figure}[h] \centering <<>>= curve(dnorm(x)) @ \caption{...
BeBlunt's user avatar
  • 25
0 votes
5 answers
271 views

How to include result values in a LaTeX document?

We are often in the following situation: a lengthy (data analysis) computation spits out a bunch of result values. Imagine a Python or script or an R script doing some resource intensive calculations. ...
lumbric's user avatar
  • 4,279
1 vote
2 answers
228 views

TinyTex from RStudio Rmarkdown knitting to pdf. "Approximately" sign in ggplot annotate throws error

Reproducible example: require(ggplot2) myggplot <- ggplot(data.frame(x=1:2, y=1:2), aes(x=x,y=y)) + geom_point() z <- 16.9 myggplot <- myggplot + annotate(geom="text", x= 1.5, ...
Reader 123's user avatar
2 votes
1 answer
63 views

How to use Sweave (knitr) with LuaLaTex?

This is a duplicate of this 5 year old question, because the answers there don't work (for me). Has someone managed to get knitr for Sweave documents (not RMarkdown) running with LuaLaTex as an engine?...
abeeisnotabug's user avatar
0 votes
0 answers
124 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 ...
Marie's user avatar
  • 25
0 votes
0 answers
43 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 ...
DeBARtha's user avatar
  • 163
1 vote
1 answer
38 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 ...
Gopala's user avatar
  • 93
1 vote
1 answer
137 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 ...
Ulrich Diez's user avatar
  • 29.6k
1 vote
0 answers
614 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 ...
Darian Voda's user avatar
0 votes
1 answer
403 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&...
17757970's user avatar
  • 323
0 votes
2 answers
555 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} \...
Devansh Kamra's user avatar
0 votes
1 answer
669 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,...
bob0901's user avatar
  • 13
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, ...
bob0901's user avatar
  • 13
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 ...
bob0901's user avatar
  • 13
2 votes
1 answer
396 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 ...
José Carlos's user avatar
1 vote
0 answers
91 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". %%%%%%%%%%%%%...
Casey's user avatar
  • 11
1 vote
1 answer
356 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. ...
hnguyen's user avatar
  • 115
2 votes
0 answers
2k 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 \...
Kris's user avatar
  • 21
0 votes
0 answers
115 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 ...
William's user avatar
8 votes
1 answer
916 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 ...
solarchemist's user avatar
0 votes
1 answer
433 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 ...
VBtech's user avatar
  • 1
1 vote
1 answer
372 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 ...
SID's user avatar
  • 11
1 vote
0 answers
178 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 ...
user avatar
2 votes
1 answer
247 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 ...
mk9y's user avatar
  • 299
2 votes
1 answer
107 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. ...
user697473's user avatar
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 ...
Gopala's user avatar
  • 93
2 votes
1 answer
89 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} \...
paulgr's user avatar
  • 21
1 vote
1 answer
370 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{...
Malte Jensen's user avatar
1 vote
1 answer
951 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 ...
mert's user avatar
  • 1,667
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 ...
Anusha's user avatar
  • 577
3 votes
1 answer
205 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. ...
Aggie Kidd's user avatar
1 vote
1 answer
153 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: ...
user1896653's user avatar
0 votes
0 answers
263 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 ...
dfrankow's user avatar
  • 233
1 vote
1 answer
193 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 ...
Chris's user avatar
  • 13
1 vote
1 answer
223 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?
statistics's user avatar
5 votes
1 answer
510 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 ...
evencoil's user avatar
  • 451
1 vote
1 answer
3k 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 ...
Wasteva's user avatar
  • 11
1 vote
1 answer
64 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'
royer's user avatar
  • 361
0 votes
0 answers
253 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} ...
tulu95's user avatar
  • 1
5 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.: ```...
Thunderbeef's user avatar
2 votes
2 answers
6k 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 ...
Quality's user avatar
  • 123
2 votes
2 answers
724 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/...
Guilherme Arbache's user avatar
0 votes
0 answers
783 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 ...
user198003's user avatar
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('...
Yobin Timilsena's user avatar
2 votes
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....
TCS's user avatar
  • 35
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 ...
Rachel Zhang's user avatar
2 votes
1 answer
212 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 ...
mf94's user avatar
  • 153
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 ...
mf94's user avatar
  • 153
2 votes
1 answer
178 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}{}{...
mk9y's user avatar
  • 299
1 vote
0 answers
532 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,...
HuiYing Chua's user avatar

1
2 3 4 5
8