13 Replies
Guest *Christian * @ 2012-06-04 08:19:58 originally posted:
Perhaps I'm not getting it right. What is the difference between read_source('file') and just an ordinary source('file')?
There is no read_source(); there is only read_chunk(). This function only reads the code; it does not evaluate the code as source() does.
Originally posted on 2012-06-04 14:25:13
Guest *mrdwab* @ 2012-07-13 17:49:08 originally posted:
Is there a way to do this with R markdown in RStudio? Currently I use ```{r echo=FALSE, eval=TRUE, comment=NA}
writeLines(readLines("path-to-r-script.R"))
It is language agnostic, meaning you can use any format including LaTeX, HTML, Markdown, ...
writeLines(readLines("path-to-r-script.R")) only reads and writes the code; it is not really read into knitr -- you have to use read_chunk() to read code chunks into knitr and reference them later.
Originally posted on 2012-07-13 19:20:49
Guest *mrdwab* @ 2012-07-14 05:18:32 originally posted:
Ok. Got it working.
Perhaps it would be useful to mention that the title and author declarations in markdown should come before set-options for proper PDF generation.
% title
% author
```{r set-options, echo=FALSE, cache=FALSE}
read_chunk(...)
```
That is the pandoc syntax. The original markdown syntax does not support that.
Originally posted on 2012-07-14 17:36:06
Guest *Phil* @ 2012-09-24 04:21:24 originally posted:
Hey Yihui,
Is it possible to do this with Python? If so, how? I have tried using the same setup as with R but read_chunk() function does n't appear to read.
Cheers,
Phil
Guest *Phil* @ 2012-09-27 05:42:12 originally posted:
Cheers Yihui, I thought I'd need engine='py' in the read_chunk settings. That doesn't make sense now...
Great package btw.
Guest *ADPowers* @ 2012-11-30 03:44:46 originally posted:
Hi Yihui, what did you use to get the formatting that way, for the R code blocks? (ie the different colors, font and layout) Do you have an example, using tikz device?
Did you see the links to Rnw source files?
But isn't that the default style in knitr? I did use tikz with external=TRUE. The syntax highlighting is a little bit different now, though.
Originally posted on 2012-11-30 07:17:30
Guest *ADPowers* @ 2012-11-30 12:26:40 originally posted:
Yeah, but all I get is plain text, indistinguishable from the rest of the document. Got no idea what is going on here. Tried to use the knit_hooks, but doesn't do anything.
I'm not really sure exactly what you want -- a minimal example? https://github.com/yihui/knitr-examples/blob/master/059-tikz.Rnw
Originally posted on 2012-11-30 16:32:14
Guest *ADPowers* @ 2012-12-01 00:34:04 originally posted:
Thanks almost got to the bottom of it. It seemed that by moving some of my standard preamble from a reference text file [which I call using include(./standard_preamble.tex)] it made the problem go away, specifically, the document class line needed to be in the actual document.This surprised me as I really didn't think that this would have been a problem, since the contents of the reference file contained no chunks, knitr settings or anything generally knitr related.
The next problem, and I'm not entirely sure this is a knitr issue, nonetheless, is that on my PC, many versions of R have been installed, knitr appears to be calling version 2.14.2, which is leading to issues with tikzDevice (built under R version 2.15.1 and not available for 2.14.2) how can I instruct latex to refer to R2.15.1?
UPDATE >> Dont worry, I worked it out.... Duh.
UPDATE >> Getting pages of errors when trying to typeset. Appears that the source is the xcolor package, since, usepackage{xcolor} works fine but usepackage[svgnames]{xcolor} or usepackage[x11names] both cause errors to be thrown.
UPDATe >> Everythings broken. Something to do with getMetricsFromLatex(TexMetrics).
UPDATE >> So finally go things sorted. Have to say, no criticism but debugging and problem solving is a hell of a lot easier in some of the OOP languages like C# or Java. Trying to work out whats going wrong in LaTeX, which is calling R, is like tying to decipher the Rosetta stone. ... All good.
UPDATE >>.On a more serious note, is there a way to control how the R output is formatted in the LaTeX Doc? Things are much better for me now, however, lines of R code are running off the page. Ie line breaks seem to be ignored???
Guest *Karl Polen* @ 2012-12-09 00:13:45 originally posted:
Hi,
I got LYX working with rnw knitr working without external files. But get this error message when trying to load an external R script.
LyX: Cannot convert file
An error occurred while running:
Rscript--verbose--no-save--no-restore "C:/Program Files (x86)/LyX 2.0/Resources/scripts/lyxknitr.R"
"C:/Users/Karl. . .
Suggestions on what I am doing wrong?
Screen clipping attached.
Thanks,
Karl
That error dialog box is not helpful; see this manual on how to debug Sweave or knitr in LyX: https://github.com/downloads/yihui/lyx/sweave.pdf
Originally posted on 2012-12-10 06:19:59
Guest *Karlpolen* @ 2012-12-10 14:19:39 originally posted:
thanks for responding
here are 2 screen shots of the detailed message logs
I've also attached a third message I frequently get about inability to delete tmp files -- in case it's relevant to how LyX and windows 7 are dealing with each other.
Guest *Karl Polen* @ 2012-12-10 14:35:44 originally posted:
figured it out!
"" instead of "/" in file path name
Guest *Leonardo Andrés Jofré Flor* @ 2012-12-17 17:14:47 originally posted:
Hello!
I tried to work with external files in lyx but I can't to get the .pdf file.
this is with you example lyx file too
The message is:
El archivo no existe: /tmp/lyx_tmpdir.MT5204/lyx_tmpbuf2/Stat579-HW8-Xie.pdf
Can you paste the full message log please? e.g. use pastebin.com
Originally posted on 2013-01-08 22:40:40
Guest *ADPowers* @ 2012-12-30 13:31:46 originally posted:
Yihui,
Trying to get Code externalization working inside LaTeX, but is giving me an 'R' error.
Error: could not find function "read_chunk".
library(knitr)
Originally posted on 2013-01-08 06:14:31
Guest *stnava* @ 2013-01-12 17:35:14 originally posted:
Hello Yihui
First, thanks so much for sharing this --- truly an amazing job.
Now, questions. I am trying to document a R package that has several functions and demos that need to be maintained and tested. I would like to employ Rrst to do this so that I can write to rst and then use sphinx to construct a searchable html website.
question 1:
is there a way to "test" if the Rrst produces the desired output? i can hack something up but do you have a general solution or a suggested way to address this need?
question 2:
background: we now need to write R functions, Rd functions and demo scripts as well. i want to define a system for my development team that reduces the amount of redundant work.
what is the best way to achieve this ? assuming i want to use Rrst and have , associated with each Rrst , a demo/file.R ... so, to be clear, demo/file.R would be associated with doc/source/file.Rrst and the content should be "the same." so a user can read the rst in html form and then open the associated .R which should be runnable.
ideally, it seems to me that i would like to write the file.Rrst script and then generate the file.R from just the R source within the Rrst ... what is a good way to extract just the R source from the Rrst?
also, i looked at spin and code externalization with knit ... however, i had problems with both
for spin , spin(s,format = c("Rrst")) seemed to produce no output at all ...
for the standard code externalization based on read_chunk, i could not determine how to "mark" the sections of code in the R script for inclusion in the Rrst .... do you have an example for this? i tried to follow the Stat579 example to Rrst but no luck.
any help appreciated! and again, thanks for the work.
b
-
I do not know what is your desired output. I use GIT to check if my output has changed since last run, e.g. https://github.com/yihui/knitr-examples In this case I only need to guarantee my first run generates the desired output.
-
see the purl() function (to extract R script from *.Rrst)
Originally posted on 2013-01-12 19:15:54
Guest *stnava* @ 2013-01-12 18:10:09 originally posted:
i have another question:
what if i don't want this:
.. {r setup}
opts_chunk$set(echo=FALSE,fig.path='figs/antsr-', fig.width=7, fig.height=4, fig.align='center', cache=TRUE, fig.show='hold', par=TRUE)
..
to appear in my output document?
is there a global knitr option to set echo=FALSE by default?
.. {r setup, echo=FALSE}
opts_chunk$set(echo = FALSE)
..
Originally posted on 2013-01-12 19:16:41
Guest *Farrel Buchinsky* @ 2013-03-19 14:05:35 originally posted:
I love the promise of knitr and Rmarkdown so that I can get away from the cut and paste nonsense of the way I used to communicate with my collaborators. I am having some problems with understanding the difference between read_chunk as opposed to source. Can you help me at http://stackoverflow.com/q/15501622/168139
Guest *jvcasill* @ 2013-05-07 17:43:30 originally posted:
The homework minimal examples no longer work in R 3.0
What error did you see? I just ran the two examples and I did not find any problems.
Originally posted on 2013-05-25 07:14:13
Guest *Karl* @ 2013-05-31 05:30:17 originally posted:
Guessing here: It may be related to the fact that tikzDevice has been pulled from CRAN, so he's probably missing that package..
Guest *Miguel A.* @ 2013-06-01 15:57:06 originally posted:
Hi,
I had this probleem and the problem was the one that Karl pointed out. I solved it installing tikzDevice, following the instructions that can be found in http://lightonphiri.org/blog/r-graphical-representation-installing-tikzdevice-package
Regards,
Guest *Sophia* @ 2013-08-20 15:12:05 originally posted:
I'm new to knitr so I'm just learning as I go. I have a large data set where I have R files that generate tables for a report. I have to write a summary report by pulling certain numbers from the tables. I don't know if I want to incorporate the R code directly into the knitr document becuase the R code has already been written and is very complicated to break up, I'd like to run the code separately instead of as a read_chunk() and have all the data and objects in my workspace. I like to be able to pull those objects into the knitr document. Do you have any suggestions on how to do that?
I do not quite recommend you to put too much code into the document. I think it is legitimate to simply source() the script. There is no need to read_chunk().
Originally posted on 2013-08-22 04:19:21
Is there a reason you use the noweb chunk definition syntax in your final example of this page? You also utilize some knitr chunk options in the name of the chunk. Are you using some fancy AWK scripts to allow yourself to write in a more traditional noweb syntax entirely, then translating it all into a knitr input document?
<<external-code, cache=FALSE>>=
read_chunk('foo-bar.R')
@
Sign in to join the discussion
Sign in with GitHub