knitr

Graphing matplotlib with Python code in a R Markdown document

混江龙づ霸主 提交于 2019-12-04 23:39:00
Is it possible to use Python matplotlib code to draw graph in RStudio? e.g. below Python matplotlib code: import numpy as np import matplotlib.pyplot as plt n = 256 X = np.linspace(-np.pi,np.pi,n,endpoint=True) Y = np.sin(2*X) plt.plot (X, Y+1, color='blue', alpha=1.00) plt.plot (X, Y-1, color='blue', alpha=1.00) plt.show() Output graph will be: Then I need to write a R Markdown to include these code and generate graph automatically after knitting the markdown. One possible solution is save the plot as a image, then load the file to markdown. ### Call python code sample ```{r,engine='python'}

Mass create documents in R markdown

拈花ヽ惹草 提交于 2019-12-04 22:47:35
问题 I'm wondering if anyone can help me with a dilemma I'm having. I have a dataset of around 300 individuals that contains some basic information about them (e.g. age, gender). I want to knit a separate R markdown report for each individual that details this basic information, in Word format. And then I want to save each report with their unique name. The actual code which sits behind the report doesn't change, only the details of each individual. For example: Report 1: "Sally is a female who is

RMarkdown / pandoc fails to knit Pdf with latex color commands

删除回忆录丶 提交于 2019-12-04 20:40:44
Mac Os: 10.11.6 R version: 3.3.1 MacTex: 2016 / TexLive: 6.2.2 RMarkdown: 1.0.9014 Knitr: 1.14 Pandoc: 1.17 RMarkdown fails to knit PDF when latex commands such as: \textcolor{blue}{Character String} are present in the .rmd file. The error output is: /usr/local/bin/pandoc +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.pdf --template ~/R/3.3/library/rmarkdown/rmd/latex/default-1.17.0.2.tex --highlight-style tango --latex-engine /Library/TeX/texbin/pdflatex --variable graphics=yes --variable 'geometry:margin

Tables and Figures side-by-side in Knitr or RMarkdown Beamer

不问归期 提交于 2019-12-04 20:05:18
问题 I am trying to create a Beamer Presentation slide in RMarkdown / Knitr . In the slide I would like to have a table and a figure placed Side-by-side , and then some more text underneath. I can only get as far as my attempt as shown in the code. I would like to have the density plot placed, next to the Hmisc Table. I am not using Kable or xtable since I get more control over the tables with Hmisc. Also, How can I adjust the text characteristics (font-size, type, color) in the individual slides?

How to only show table caption once in “list of table” for a table split onto multiple pages

此生再无相见时 提交于 2019-12-04 19:08:46
I am using R packages ( xtable and knitr ) and Latex packages ( longtable and hyperref ) to prepare a document. One of my tables is very long and splits onto multiple pages. It turned out that the "List of Table" shows every page number at which this table appears, but all hyperlinks bring me to the beginning of this table. My question is, in "List of Table" how can I just show the first page number at which this table appears. \documentclass{article} \usepackage{longtable} \usepackage{hyperref} <<setup, include=FALSE, cache=FALSE>>= library(knitr) library(xtable) @ \begin{document}

How to add multiple figures across multiple pages in a chunk using knitr and RMarkdown?

为君一笑 提交于 2019-12-04 18:07:03
问题 I am using a for loop to create multiple big figures across multiple pages in one chunk with knitr and rmarkdown. It works fine for word and html outputs, but has one problem in pdf output. This is a minimal RMarkdown example to reproduce my problem. --- title: "Knitr test" date: "6 April 2015" output: pdf_document --- ```{r, echo=FALSE, fig.width=6.5,fig.height=10} library(ggplot2) for (i in seq(1, 4)){ p <- ggplot(cars, aes(speed, dist)) + geom_point() print(p) } ``` The generated pdf file

How do I access the data from a file passed as parameters in a RMarkdown document?

混江龙づ霸主 提交于 2019-12-04 18:06:51
问题 Following the last example on RMarkdown's Parametrized Reports page, I am trying to use the Shiny interface to select my input file with the following code inside the YAML header: params: data: input: file label: 'Input dataset:' value: myData.csv The Shiny interface shows up and I get to browse for a file, but when I try to access it further down in the R code via read.csv(file=params$data, header=TRUE) , I get the following message: Error in file(file, "rt") : cannot open the connection How

How can I remove the prefix (index indicator) [1] in knitr output?

北慕城南 提交于 2019-12-04 17:08:12
问题 Standard R output looks like this > 3 [1] 3 To remove the prefix 1 you can use > cat(3) 3 Is there a way to remove this globally? Or do you have to wrap cat() around everything? Further to that, I'm using this within knitr, so if there isn't an R global setting, there may be a knitr wide setting, I did look, but couldn't see one. Edit: It was asked why one would want this, something like if you wanted to structure a report like the below. The [1] is just not needed and means nothing to none R

Creating R tables with embedded graphics

送分小仙女□ 提交于 2019-12-04 16:54:19
I'd like to be able to create a table with one of the columns being graphical, others text. Ideally, I'd create an excel spreadsheet, but I'm pretty sure that none of the R to Excel packages can write PDFs into cells. I think I can hack something together using Knittr or Sweave, though I don't know how, exactly. Any advice? I've tried to reproduce your example : So I've looked into the R dataset, and used a baseball dataset, though I have the nagging doubt that for baseball players, the g-r might look really stupid... Anyway I produced two examples of the use of the get_bar_df function, and

knit DT::datatable without pandoc

大兔子大兔子 提交于 2019-12-04 16:50:56
问题 I am trying to use DT::datatable to output a nicely formatted, interactive table in R. ...only problem is that I want a heroku job to knit the document for me, and I've learned that RStudio and rmarkdown::render() use pandoc under the hood -- but pandoc doesn't ship in the stripped down R Buildpack for heroku. Is there any way to get the old markdown engine ( knitr:knit2html or markdown:markdownToHTML ) to pass the javascript that powers datatable through? Or to be more precise, to generate