Hot answers tagged

93

I think this is the easiest option! --- title: "Title" author: "Me" header-includes: - \usepackage{bbm} output: pdf_document --- (Edited to have three, instead of four, hyphens to open and close the YAML front-matter)


48

Following Yihui's advice, I found the best option to be to invoke the warning=F and message=F chunk options, like so: ```{r, message=F, warning=F} library(memisc) ``` This was using knitr ("Knit HTML") with RStudio to process R markdown.


35

As per this page on the R Markdown website, you can add whatever you want to the preamble via the in-header option in the YAML header; e.g., ---- title: "Titre" date: Fecha output: pdf_document: includes: in_header: mystyles.sty ---- In mystyles.sty, located in the same directory as the .Rmd, you could have a whole list of ...


27

Try adding fig_caption: yes to the YAML header of your .Rmd file. It will look something like this: --- title: "Untitled" author: "Nicholas" date: "20/09/2014" output: pdf_document: fig_caption: yes --- There's more information here: http://rmarkdown.rstudio.com/pdf_document_format.html


25

If all you want is two figures side by side, you can put the code in one chunk and set fig.show='hold' with an appropriate width, e.g. \documentclass{article} \begin{document} <<test, out.width='4cm', out.height='4cm', fig.show='hold'>>= plot(1:10) plot(rnorm(100)) @ \end{document} If you want to center the figures, just add an option fig....


22

With Sweave really you need only two steps for a simple document as this my_sweave_file.Rnw: \documentclass{article} \begin{document} Some text <<RTest>>= 2+2 @ \end{document} From the command line is enough: R CMD Sweave my_sweave_file.Rnw pdflatex my_sweave_file.tex Or even only one: R CMD Sweave --pdf my_sweave_file.Rnw In case that you ...


21

fig.lp is not the label of the figure, it is the prefix that is used to create the label. From the description of knitr options fig.lp: ('fig:'; character) label prefix for the figure label to be used in \label{}; the actual label is made by concatenating this prefix and the chunk label, e.g. the figure label for <<foo-plot>>= will be fig:foo-...


19

Renaming using \let Name clashes can be resolved by renaming. In this case these are simple environments. An environment name defines two macros \name and \endname (the latter can also left undefined, because it is called via \csname). \documentclass{exam} \newcommand*{\renameenviron}[1]{% \expandafter\let\csname exam-#1\expandafter\endcsname \...


18

This post is rather lengthy. I will attempt to address both of your main questions. Sorry for the novel ... Question 1 The following example tries to plot the same thing three times: First without tikzDevice and then in two tikzDevice-ways. The tikzDevice-slides are not very nice looking, which I can improve by manipulating the widths and heights. But ...


16

I have solved it. The command I use in the user-defined commands for compiling and displaying a Rnw-file in my own pdf-viewer is : "C:/whateverYourPathToRonYourMachineIs/R-3.0.1/bin/Rscript.exe" -e "library(knitr); knit2pdf('%.Rnw')" | pdflatex -synctex=1 -interaction=nonstopmode %.tex | "C:/whateverYourPathToYourPDFViewerOnYourMachineIs/Foxit Reader.exe" "...


13

knitr has a few pretty straightforward ways of handling this. Option 1: Using knit_child() with inline R code Say your setup is like the following. In the same directory, you have: graph.R ## ---- graph library(ggplot2) CarPlot <- ggplot() + stat_summary(data= mtcars, aes(x = factor(gear), y = mpg ...


13

(Upgraded from a comment.) Just use library("knitr"); knit("file.Rnw") in the console (where "file.Rnw" is the name of your Sweave file, of course). This will produce "file.tex" in the working directory.


13

If you look at your example, the table does not have a number. I assume you want to reference the table number, so first we must give the table a number. To do this, use the caption argument. Second, when using xtable, you have to be careful with which arguments you want to give to xtable and which arguments to print.xtable. You are currently passing the ...


12

The following solution sets up an environment blocktable derived from longtable that provides the desired functionality using LaTeX only. Implementation notes First, a few counters are needed: \newcounter{@tabrow} \newcounter{@emptyrow} \newcounter{@modulus} \newcounter{@default@blocksize} @tabrow will be incremented every row to determine the current ...


11

Remove \SweaveOpts{concordance=TRUE} in your Rnw file. It is invalid and useless to knitr. Update: I have fixed the plot problem in the development version (v1.2.4). See here for instructions on installation. It will go to the stable version 1.3 eventually, but perhaps not until a month later.


10

This is the answer I arrived at with the help of @baptiste and it works just like I wanted it to. \begin{frame} \begin{columns} \begin{column}{.5\linewidth} Text \end{column} \begin{column}{.5\linewidth} <<echo=FALSE,eval=TRUE,out.width='4cm',out.height='4cm'>>= plot(1:10) @ \end{column} \end{columns} \end{frame}


10

With \lstdefinestyle you can define as many styles as you wish; then you can use \lstnewenvironment to define new listing environments using those new styles; in this way you can easily change the styles for your listings as required. You can still use \lstset to set general settings (applicable to all the listings). A simple example: \documentclass[]{...


9

I do not see the extra white page you mentioned: \documentclass[a4paper]{article} \usepackage{fullpage} \usepackage{pdflscape} \begin{document} \begin{landscape} <<test, out.width='1\\linewidth', fig.width=7, fig.height=4>>= par(mar=c(4, 4, .1, .1)); plot(1:10) @ \end{landscape} \end{document}


9

The following is my first thought, but I feel fairly certain that a better way exists: \documentclass{article} \begin{document} <<makegreek>>= greek <- c("$\\alpha$", "$\\beta$", "$\\gamma$") greek @ <<r grecoroman>>= gr <- data.frame(roman=letters[1:3], greek=greek) gr @ <<gr-table, results='asis'>>= library(...


9

Since you are using knitr, the simplest thing is to add \\ every tenth row using add.to.row parameter of print.xtable. This is a very rough code; in the general case you need also to check that MatrixData has more than 10 rows. \documentclass{article} \usepackage{longtable} \begin{document} \listoftables << label=LongTable, results='asis', echo =...


8

RStudio allows you to use a custom LaTeX program with that you can set up a script that does the proper processing there are automatic solutions for this, e.g. latexmk, like so: Sys.setenv(RSTUDIO_PDFLATEX = "/Library/TeX/texbin/latexmk") (or whatever you path may be) Another option is that RStudio allows to specify build tools for a project. This may be ...


8

I would define a new column as in the following example. The newcolumntype command can be very useful for achieving the sorts of affects you're looking for. \newcolumntype{B}{>{\begin{minipage}[b]{6.6cm}\raggedright{}}c<{\end{minipage}}} It's not essential to use \raggedright, but I think fully justified text in rather narrow columns looks ...


8

Just found the solution myself: Someone can set the point size for tikzDevice manually — With knitr, this is done by adding dev.args=list(pointsize=12) to the chunk options. Hope this will help someone ;)


8

TeXstudio is mainly focused on LaTeX. Rnw is only supported in the syntax highlighting (because this was quite easy to implement), but it is not explicitly handled in the semantic parsing or the workflow. You cannot make TeXstudio recognize these commands without modifying the source code, because these things are partly hard-coded into TXS. Of course, you ...


8

Try the following code: library(memisc, warn.conflicts = FALSE, quietly=TRUE) or suppressMessages(library(memisc, warn.conflicts = FALSE, quietly=TRUE))


8

I'm still new to LaTeX (about 2 years of use) but have found knitr very helpful for: inline code code chunks - incredibly helpful for execution and then interspersing your document with it dead simple graph integration into document caching (I'm sure you could do this with make by watching file changes) an amazingly responsive support community (at least on ...


8

As of rmarkdown version 1.4 it has been possible to use the extra_dependencies parameter to list a character vector of LaTeX packages. This is useful if you need to load multiple packages: --- title: "Untitled" output: pdf_document: extra_dependencies: ["bbm", "threeparttable"] --- If you need to specify options when loading the package, you can add ...


8

It suggests that you have at least two code chunks with the same label match, like this <<match>>= @ <<match>>= @ Duplicate labels are not allowed in knitr.


8

Updated answer This is Enigma. Notice that Enigma is symmetric. Thus you can encode and decode at the same place. In the following example, the first input AN ENIGMA MACHINE... comes from the Wikipedia article. And then I copied and pasted the output ISWXACOIOIGKAXHF...to be the second input. Thus we got ANENIGMAMACHINE as the second output, which is what ...


7

You can directly set your listings settings in your .Rnw file. Here I have defined a new style Rsetings. \lstdefinestyle{Rsettings}{ basicstyle=\ttfamily, breaklines=true, showstringspaces=false, keywords={if, else, function, theFunction, tmp}, % Write as many keywords otherkeywords={}, commentstyle=\itshape\color{Rcommentcolor}, keywordstyle=...


Only top voted, non community-wiki answers of a minimum length are eligible