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
1 vote
1 answer
20 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 ...
user avatar
  • 23.5k
0 votes
0 answers
44 views

How to include an algorithm in a Rmarkdown template [closed]

I have the following document. I am using the arxiv_article style. This is a predefined template that comes with the rticles package. I am trying to insert some Latex, but I am running into an error. ...
user avatar
  • 101
1 vote
0 answers
47 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 ...
user avatar
0 votes
1 answer
68 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&...
user avatar
  • 141
0 votes
2 answers
88 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} \...
user avatar
0 votes
1 answer
46 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,...
user avatar
  • 13
0 votes
1 answer
65 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, ...
user avatar
  • 13
1 vote
0 answers
21 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 ...
user avatar
  • 13
0 votes
0 answers
36 views

Highlighting R Syntax in .Rnw file

I'm trying to write my lecture slides using beamer (knitr/sweave). However, when I'm adding the R syntax, the most I can do is boxing it, but I want to have my syntax highlighted. Something that is ...
user avatar
0 votes
0 answers
44 views

textcolor inside bookdown math blocks

I am trying to get text coloring to work inside tex/math blocks. The code I inherited in latex is \[ H_0: b = \textcolor{orange}{0} \] This works fine for pdf but not for html. I have then read https:...
user avatar
2 votes
1 answer
103 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 ...
user avatar
1 vote
0 answers
43 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". %%%%%%%%%%%%%...
user avatar
  • 11
1 vote
1 answer
161 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. ...
user avatar
  • 115
0 votes
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 \...
user avatar
  • 1
0 votes
0 answers
39 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 ...
user avatar
4 votes
1 answer
246 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 ...
user avatar
0 votes
1 answer
175 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 ...
user avatar
  • 1
1 vote
1 answer
127 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 ...
user avatar
  • 11
1 vote
0 answers
115 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
0 votes
1 answer
150 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 ...
user avatar
  • 279
2 votes
1 answer
55 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. ...
user avatar
1 vote
2 answers
947 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 ...
user avatar
  • 81
2 votes
1 answer
61 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} \...
user avatar
  • 21
1 vote
1 answer
202 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{...
user avatar
1 vote
1 answer
524 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 ...
user avatar
  • 1,627
1 vote
2 answers
2k 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 ...
user avatar
  • 577
3 votes
1 answer
115 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. ...
user avatar
1 vote
1 answer
84 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: ...
user avatar
0 votes
0 answers
149 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 ...
user avatar
  • 223
1 vote
1 answer
128 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 ...
user avatar
  • 13
1 vote
1 answer
170 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?
user avatar
5 votes
1 answer
325 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 ...
user avatar
  • 411
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 ...
user avatar
  • 11
1 vote
1 answer
43 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'
user avatar
  • 347
0 votes
0 answers
222 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} ...
user avatar
  • 1
4 votes
1 answer
1k 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.: ```...
user avatar
2 votes
1 answer
3k 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 ...
user avatar
  • 123
2 votes
2 answers
485 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/...
user avatar
0 votes
0 answers
579 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 ...
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('...
user avatar
1 vote
1 answer
758 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....
user avatar
  • 25
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 ...
user avatar
2 votes
1 answer
157 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 ...
user avatar
  • 153
2 votes
2 answers
771 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 ...
user avatar
  • 153
2 votes
1 answer
148 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}{}{...
user avatar
  • 279
1 vote
0 answers
393 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,...
user avatar
1 vote
1 answer
489 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 ...
user avatar
  • 21
1 vote
0 answers
361 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'...
user avatar
  • 11
2 votes
1 answer
515 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 ...
user avatar
1 vote
3 answers
9k views

Can I type \LaTeX inside inline code in Rmarkdown?

I know I can use $$ to write \LaTeX in Rmarkdown documents like $\beta$. My goal is if this is possible inside inline code. I would do `$\beta$` or `$\\beta$`, but both do not work. In case it is ...
user avatar
  • 877

1
2 3 4 5
8