How to Start Using (pgf)Sweave in LyX in One Minute | /en/2010/10/how-to-start-using-pgfsweave-in-lyx-in-one-minute/
How to Start Using (pgf)Sweave in LyX in One Minute
https://yihui.org/en/2010/10/how-to-start-using-pgfsweave-in-lyx-in-one-minute/
https://yihui.org/en/2010/10/how-to-start-using-pgfsweave-in-lyx-in-one-minute/
访客 *reader0527* @ 2010-11-04 09:48:20 写道:
被嫌弃R版本过低了。。。
This script requires at least R 2.11.1; please update your R first.
In fact we do not really need R >= 2.11.1. I intentionally put an error message here to remind you that you need to update your R -- generally it is a very bad habit to work with old versions of software.
Originally posted on 2010-11-04 19:51:34
Guest *stevepowell* @ 2010-12-27 03:58:01 originally posted:
hmm, but on ubuntu 10.04, only 2.10 is in the repositories and I usually wait until those are updated. Any way of running your interesting script on 2.10?
Of course. I have updated my script. Please try again. I still recommend you to use the latest version of pgfSweave (>=1.1.1), anyway.
Originally posted on 2010-12-27 04:07:15
Guest *liyun* @ 2010-11-06 18:27:11 originally posted:
I failed to configure it with Tex Live 2010, R x64 2.12.0, windows7 and Lyx 1.6.4.....help!!!!!!!!!!
I assumed Windows users would use MikTeX... initexmf is only a command for MikTeX.
I guess it should not be too difficult for TeXLive -- just put the downloaded texmf folder under your home directory (usually it is C:Usersyour.username) and everything should be OK.
Originally posted on 2010-11-06 18:57:41
Guest *liyun* @ 2010-11-06 18:29:13 originally posted:
it seems that tex live doesn't support "mikreport = system("initexmf --report", intern = TRUE)"
I've added support for TeXLive under Windows, but I didn't test it because TeXLive is too big for me -- I don't want to install it.
You can source() the code again and tell me if there are any problems. Thanks!
Originally posted on 2010-11-07 04:58:37
Guest *liyun* @ 2010-11-17 00:32:13 originally posted:
perfect!!! Thank you. It is really amazing.
Guest *AMANDE* @ 2010-11-17 20:12:37 originally posted:
Rien à dire ! c'est parfait comme référence pour faire du sweave avec LyX.
Merci beaucoup !
Guest *Janko* @ 2010-11-24 15:47:08 originally posted:
Kudos, really awesome post!
One question though: Lyx 2.0 beta says it features Sweave out-of-the-box (http://wiki.lyx.org/LyX/NewInLyX20). I couldn't figure out just quite how to use it though (there are some relevant converters listed, but how do I use them?). On the page it says "To this end, one has to select the Noweb or literate modules.". Can you tell me what this actually means?
I installed LyX 2.0 beta and found this version has got an R script in it to run Sweave, and they have added native support to Sweave in LyX; you may take a look at http://www.lyx.org/trac/browser/lyx-devel/trunk/lib/layouts/sweave.module The Sweave converters are defined internally, i.e. no more hacking needed. I'm not satisfied with the R script they provided, though.
Now Noweb and Sweave are separate from each other, which was not possible in the past: you can only use one of them.
It seems I will need some big changes to my configuration in this blog post when LyX 2.0 is released.
Originally posted on 2010-11-30 22:12:09
Guest *Liv* @ 2010-12-08 09:50:42 originally posted:
Doesn't it help when you load both Sweave and Noweb modules?
I don't use Noweb, so it does not bother me at all. Currently LyX (1.6.x) only has one type of literate programming, which should be either Sweave or Noweb. Maybe it is possible to have both of them in a single document. I have no idea... I only know they will become two separate modules in LyX 2.0.
Originally posted on 2010-12-08 10:12:44
Guest *gavenin* @ 2011-04-14 18:58:54 originally posted:
What exactly is the link between noweb and sweave (R function) ?
In 1.6 both were integrated in literate?
In Lyx 2 I only need sweave modulen?
My Class modele is still literate?
bests regards
gavenin - you may think Noweb as the father of Sweave; the idea of Sweave in R was largely borrowed from Dr Knuth's literate programming, and the syntax of Sweave in LaTeX was borrowed from Noweb: http://en.wikipedia.org/wiki/Noweb
The difference of implementation of Sweave in LyX between 1.6.x and 2.0 is that it becomes a separate module in 2.0, which means it can be used with arbitrary document classes (add a module to your document and this document becomes a literate programming document). In 1.6.x, you have to write a layout for each document class.
As a Sweave user, you do not really need to know what Noweb is.
Originally posted on 2011-04-15 04:27:42
Guest *MartinInFrankfurtaM* @ 2010-12-14 20:21:30 originally posted:
You have options to turn on/off caching or evaluation for the code chunks: cache=FALSE can turn off caching, and eval=FALSE will make R not evaluate the code chunk.
Originally posted on 2010-12-16 08:03:20
Guest *MartinInChemnitz* @ 2010-12-23 03:18:29 originally posted:
Thank you, Yihui!
Guest *Trang Le* @ 2010-12-22 20:07:46 originally posted:
Yihui,
How did you install Lyx 2.0 beta? I only found documents about it on the web but no installation option.
Could you guide me to the right direction?
Thanks
ftp://ftp.lyx.org/pub/lyx/devel/lyx-2.0/beta2/
I don't recommend the beta version, though. The final version is scheduled to arrive early next year.
Originally posted on 2010-12-22 23:53:47
Guest *MartinInChemnitz* @ 2010-12-23 03:49:05 originally posted:
Yihui,
Using pgfsweave now with Lyx 1.6.8 on openSuse 11.2 x86_64 installed following your script,
I found some strange "feature" regarding comments and CR's.
It depends on the fact that I ident my code by hand and use "keep.source=T" rather than "tidy=T".
I can reproduce it with your Lyx-pgfSweave-minimal-demo here.
If I use ← (Ctrl/Enter) to start a new line in a scrap section,
pgfsweave only goobles the trailing comment lines at the end of the scrap section.
If I use "Enter" to start a new line in a scrap section, as in your demo file,
pgfsweave blanks lot of lines including code except the R prompt.
This is a long story... I explained in another post early this year: http://yihui.name/en/2010/02/press-enter-in-lyx-sweave-as-you-wish/
I don't recommend you really read that boring technical post. For the time being, just use SweaveOpts{tidy=TRUE} and options(keep.blank.line = FALSE) in the first code chunk. If you do not think this option makes much sense, I suggest you wait for one or two months until the final release of LyX 2.0. The problem of blank lines will be fixed in LyX 2.0. I will also adjust my configuration script then.
Originally posted on 2010-12-25 03:46:44
Guest *sma* @ 2010-12-24 03:30:03 originally posted:
required LaTeX packages installed
required LyX layouts installed
Error in file(con, "w") : cannot open the connection
In addition: Warning messages:
1: In file.create(to[okay]) :
cannot create file '/Users/sma/.lyx/scripts', reason 'No such file or directory'
2: In file(con, "w") :
cannot open file '/Users/sma/.lyx/preferences': No such file or directory
Sorry, this is a bug in my script. I've fixed it. Please try it again and let me know if there are still problems. I don't have a Mac OS at hand, so I'm unable to test the code.
Originally posted on 2010-12-25 03:57:39
Guest *sma* @ 2010-12-26 02:24:27 originally posted:
OMG, you do really reply every question! But so sorry, this time they have these new error warnings +_+:
required LaTeX packages installed
required LyX layouts installed
Error in file(con, "w") : cannot open the connection
In addition: Warning messages:
1: In file.rename(file.path(tmpDir, pkgname), instPath) :
cannot rename file '/Users/sma/Library/R/2.12/library/file5c89bf68/pgfSweave' to '/Users/sma/Library/R/2.12/library/pgfSweave', reason 'Directory not empty'
2: unable to move temporary installation '~/Library/R/2.12/library/file5c89bf68/pgfSweave' to '~/Library/R/2.12/library/pgfSweave'
3: In file.create(to[okay]) :
cannot create file 'Library/Application Support/LyX-1.6/scripts', reason 'No such file or directory'
4: In file(con, "w") :
cannot open file 'Library/Application Support/LyX-1.6/preferences': No such file or directory
The first two warnings are not my fault; maybe you can try to remove the pgfSweave package first (e.g. remove.packages('pgfSweave'))
The last two warnings have been fixed just now. Please try the script again. Thanks!
Originally posted on 2010-12-26 03:52:49
Guest *sma* @ 2011-01-13 20:43:39 originally posted:
Hey Yihui, I'm back 'cause the new errors. I've tried to the configuration with you hints again. After running the "source(...)" something are downloaded and installed, but it shows in R:
required LaTeX packages installed
required LyX layouts installed
LyX preferences updated
Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called 'pgfSweave'
Despite of this I tried to compile your “minimal demo” in Lyx, then I've got another error like:
An error occurred whilst running Rscript '/Users/sma/Library/Application
Support/Ly
TO THE OTHER READERS: Has anyone finished it successfully under Mac OS?
It seems you did not succeed in installing the R package pgfSweave; can you try install.packages('pgfSweave') in R and see what happens?
Originally posted on 2011-01-13 22:14:04
Guest *avenin* @ 2011-02-27 01:20:33 originally posted:
Hello I am running 10.6, R2.12 MAC tex is properly installed and Lyx run well
I run the command and have just to ask for an installation in user/library (and not in the framework one to make the remark above disapear. Therefor I was full of hope, but when running the demo file : an error occurred while executing R script
I went to '/Users/glfxxx/Library/Application Support' and find the R script indicate in the Lyx preference as followed :
Rscript '/Users/glfxxx/Library/Application Support/LyX-1.6/scripts/lyx-sweave-exec.R' 'UTF-8' 'pgfSweave' $$r $$p $$i > $$i.log 2>&1
I then tried to execute lyx-sweave-exec.R in R and had the following answer
Error in if (.cmdargs[2] == "pgfSweave") { :
missing value where TRUE/FALSE needed
I am at this point out of my capabilities, so if you had any suggestion, I would be grateful
Regards and congratulations for your blog
Guillaume
Guillaume
This is a pain caused by spaces in the path to the R script. As I don't use Mac OS, it's difficult for me to decide where to put the script lyx-sweave-exec.R. Under Linux, I can simply put it under ~/.lyx/scripts.
What you can do is to move this script file to a path which does not contain spaces, and open /Users/glfxxx/Library/Application Support/LyX-1.6/preferences, then modify the old path of the script to the new path. Or you can do this from the menu of LyX.
Originally posted on 2011-03-04 11:56:07
Guest *avenin* @ 2011-04-11 00:50:03 originally posted:
It helps, but I can't still compil
In red , I can read
prefix.string=Rfig,echo=FALSE,results=hide,cache=FALSE,pdf=FALSE,eps=FALSE,tidy=TRUE,external=TRUE
It seems that The converter is not properly called. Did I miss something
For no sweave document, I can compile.
regards and many thanks for your reply.
Guest *avenin* @ 2011-04-12 04:52:38 originally posted:
Ok I understand, my error, I did not modify document's properties properly.
I am running Lyx2 and I get the following error
Literate->Latex converter missing.
I tried to past manually in the preference
# FORMATS SECTION #############################
#
format "literate" "Rnw" "Sweave" "" "editor" "editor" "document"
format "r" "R" "R/S code" "" "editor" "editor" "document"
format "latex" "tex" "LaTeX (plain)" "" "editor" "editor" "document"
format "pdflatex" "tex" "LaTeX (pdflatex)" "" "editor" "editor" "document"
#
# CONVERTERS SECTION ##########################
#
converter "literate" "r" "R CMD Stangle $$i" ""
converter "literate" "latex" "R CMD Sweave $$i" ""
converter "literate" "pdflatex" "R CMD Sweave $$i" ""
but without any success
I could appreciate that your program did a good job by creating in this file :
converter "sweave" "latex" "Rscript '/Users/me/Library/Application Support/LyX-2.0/scripts/lyx-sweave-exec.R' 'UTF-8' 'pgfSweave' $$r $$p $$i" ""
converter "sweave" "pdflatex" "Rscript '/Users/me/Library/Application Support/LyX-2.0/scripts/lyx-sweave-exec.R' 'UTF-8' 'pgfSweave' $$r $$p $$i" ""
converter "sweave" "r" "Rscript '/Users/me/Library/Application Support/LyX-2.0/scripts/lyx-sweave-stangle.R' 'UTF-8' 'formatR' $$r $$p $$i" ""
converter "sweave" "xetex" "Rscript '/Users/me/Library/Application Support/LyX-2.0/scripts/lyx-sweave-exec.R' 'UTF-8' 'pgfSweave' $$r $$p $$i" ""
If you can help me to corret the converter script I would be very thankfull
regards
GA
Hi, I think the error comes from the space in the path of the R script. I'll explain by email in a minute.
Originally posted on 2011-05-08 08:59:37
Guest *MartinInChemnitz* @ 2011-01-05 04:44:59 originally posted:
Yihui,
Thank you for your patience! Do you accept donations?
Brachiating along your transparent "lyx-sweave-config.R" did provide more confidence than blindly trusting that very thing would work in opensuse. I can open LyX-pgfSweave-demo-Yihui-Xie.lyx, compile and view it.
Could you please have a look at the output below that I get in the command window while opening "LyX-pgfSweave-demo-Yihui-Xie.lyx", compiling and viewing it?
~/Documents> lyx
as soon as I open LyX-pgfSweave-demo-Yihui-Xie.lyx, I get:
LyX: Unknown InsetLayout tag [around line 101 of file ~/Documents/Lyx/tmp/lyx_tmpdir.hX2697/convert_layout.nn2697 current token: 'ParbreakIsNewline' context: '']
LyX: Unknown InsetLayout tag [around line 102 of file ~/Documents/Lyx/tmp/lyx_tmpdir.hX2697/convert_layout.nn2697 current token: '1' context: '']
GPL Ghostscript 8.64: Unrecoverable error, exit code 1
dvipng warning: No GhostScript pngalpha output, cannot render raw PostScript GPL Ghostscript 8.64: Unrecoverable error, exit code 1
GPL Ghostscript 8.64: Unrecoverable error, exit code 1
I do have Ghostscript installed!
The file ~/Documents/Lyx/tmp/lyx_tmpdir.hX2697/convert_layout.nn2697 does not exist and when I create it containing 1 space and monitor it with "tail -f", nothing is ever written there.
Is there some path wrong?
After I compile for the first time, I get
dvipng warning: No GhostScript pngalpha output, cannot render raw PostScriptGPL Ghostscript 8.64: Unrecoverable error, exit code 1
This is BibTeX, Version 0.99d (TeX Live 2010)
The top-level auxiliary file: LyX-pgfSweave-demo-Yihui-Xie.aux
The style file: jss.bst
Database file #1: 0_home_andreas_Downloads_pgfSweave_LyX-pgfSweave-demo_LyX-pgfSweave-demo-Yihui-Xie.bib
This is BibTeX, Version 0.99d (TeX Live 2010)
The top-level auxiliary file: LyX-pgfSweave-demo-Yihui-Xie.aux
The style file: jss.bst
Database file #1: 0_home_andreas_Downloads_pgfSweave_LyX-pgfSweave-demo_LyX-pgfSweave-demo-Yihui-Xie.bib
What follows, depends on the choice of the icon that I use for compilation.
Is my installation ok or are there any log or configuration files that I need to check.
Is there some easy route to understand this?
I feel I had better understand this before taking the next debugging dive into my own lyx files.
Hi,
I will certainly not turn down donations; follow this link if you use PayPal. Thanks!
ParbreakIsNewline is a new tag in LyX 2.0 (beta version), which is not available in LyX 1.6.x. To turn off the warnings about this tag, you can remove the line in ~/lyx/layouts/literate-scrap.inc
For the GhostScript problem, I really have no idea. Having Googled for a while, it seems you are not the only one who had this problem. I suggest you ask in the LyX mailing list: lyx-users@lists.lyx.org
I've been using Ubuntu and do not have an openSUSE system to test the problem.
Originally posted on 2011-01-07 02:20:59
Guest *MartinInChemnitz* @ 2011-01-07 14:43:33 originally posted:
Thank you Yihui,
update:
I could upgrade to ghostscript 8.70 without further ado within opensuse 11.2 but this did not help. The next step that is available in opensuse 11.2 is ghostscript 9.0 but that involves resolving several dependencies by hand. I consider that a nogo area.
In the lyx file itself, the ghostscript error depends on leaving the math-mode from the first numbered display equation.
begin{eqnarray*} ... end{eqnarray*}
is fine
begin{eqnarray} ... end{eqnarray}
is not.
Thank you for your suggestion to post.
Guest *MartinInFrankfurtaM* @ 2011-01-08 05:26:43 originally posted:
No need to post at lyx-users@lists.lyx.org
The bug is well known and thought to be harmless.
(http://www.mail-archive.com/lyx-users@lists.lyx.org/msg81088.html)
I have learned where to look - but learning a lot makes you grow very old.
Thanks. This is really a weird problem...
Originally posted on 2011-01-08 07:04:48
Guest *MartinInChemnitz* @ 2011-01-10 12:39:39 originally posted:
Yihui,
Regarding your "Bad News 3" (large pictures):
If the tikz-format is more wasteful with computer resources than ps/pdf, what are the benefits of storing the graphics in this vectorized format?
If I need to change anything, it will be at the ggplot level anyway.
Is there perhaps an option to condense "large" graphics from tikz to ps/pdf for semifinal inclusion into the literate-programming Lyx file while I proceed to the next chapter?
The major advantage of using Tikz in Sweave is that the font style of the plots is completely consistent with the LaTeX output. This is one thing I care a lot about. I do not like the fonts used in R. There are other elements which are consistent with LaTeX too in terms of the style. See the vignette of the tikzDevice package.
For the second question, you can use the option external = TRUE so that pgfSweave will convert the tikz graphics into PDF, and these plots will be cached as well. (Note my original code externalize = TRUE is a typo)
Originally posted on 2011-01-11 01:03:51
访客 *liyun* @ 2011-01-17 15:31:45 写道:
Another additional point: the environment variable... I still need to add R's path to PATH system variable manually, say c:Progra~1RR-X.Y.Zbin.
Moreover, I cannot use it now after reinstalling my windows and r and textlive and lyx... the error reports:
Creating new TikZ metrics dictionary in:
D:/my documents/economics courses/Econometric Methods I/.tikzDict-demo
Error in file(texLog, "r") : 无法打开链结
此外: 警告信息:
In file(texLog, "r") :
无法打开文件'C:DOCUME~1ADMINI~1LOCALS~1TempRtmpJZN9eN/tikzStringWidthCalc.log': No such file or directory
错误于driver$runcode(drobj, chunk, chunkopts) :
Error in file(texLog, "r") : 无法打开链结
Calls: pgfSweave -> Sweave ->
收捲时出错: Take a look at the error log file: C:/Documents and Settings/Administrator/Local Settings/Temp/lyx_tmpdir.Hp3880/lyx_tmpbuf0/demo.Rnw.log
停止执行
The code to set the PATH variable is:
system(paste('setx PATH "', normalizePath(file.path(R.home(), 'bin')), ';',
Sys.getenv('PATH'), '"', sep = ''))
This should not fail for Win XP with SP2 and Win Vista/7.
source('http://gitorious.org/yihui/lyx-sweave/blobs/raw/master/lyx-sweave-config.R') If you run into errors, R will open the error log automatically.BTW, you may also need to update the pgfSweave package. Let me know if you still have problems.
Originally posted on 2011-01-18 00:35:47
Guest *liyun* @ 2011-01-18 01:43:01 originally posted:
I don't know.... I copied the link above (source('http://gitorious.org/yihui/lyx-sweave/blobs/raw/master/lyx-sweave-config.R')) to R and let it run. Then, I still need to set the environment variable manually. I'm using xp now.
Yes. R will open the error log automatically, and the error report above was copied from the opened log file. I updated pgfSweave since after the re-installation of my windows system, I have nothing left....So every package I have now should be at the latest version.
I cannot process them. That's the only question at present.... everytime I end up with the error report log file....
Guest *liyun* @ 2011-01-19 00:15:13 originally posted:
I don't know why, but R CMD Sweave $$i works....so maybe there is something wrong with pgfSweave. By the way, it required me to install a package kinship again...
What is the error message after you run the configuration script again?
The installation of the package kinship might be due to the fact that this configuration requires you to update all your R packages. pgfSweave does not depend on kinship, anyway.
Originally posted on 2011-01-19 03:12:02
Guest *Shelly* @ 2011-02-05 04:07:53 originally posted:
Hope the script - lyx-sweave-config.R can also set up a document class in Lyx for Beamer application.
I do have an experimental class for Beamer which I did not put in the configuration, because currently I have not found an elegant way to specify the 'fragile' option for a beamer slide. You know the Sweave output in Beamer slides has to be protected by the fragile option. Here is an example produced in LyX/Sweave: http://yihui.name/en/wp-content/uploads/2010/10/animation-2011-Yihui-Xie.pdf
I can put the experimental class in the config script if you are really eager to try.
Originally posted on 2011-02-06 01:16:32
The beamer support has been added; you can run the config script again to see it.
I borrowed the solution from this discussion:
http://comments.gmane.org/gmane.editors.lyx.general/65378
I have a demo here:
http://gitorious.org/yihui/lyx-sweave/blobs/master/demo/animation-2011-Yihui-Xie.lyx
Originally posted on 2011-02-06 23:42:22
Guest *Shelly* @ 2011-02-07 04:54:25 originally posted:
Thanks! Yihui.
Your solution works well.
And I just did my homework, too, to google another solution with this link:
http://ggorjan.blogspot.com/2008/09/using-beamer-with-lyx-sweave.html
It works fine, too.
Have you tried to place, for example, the animated graphics as described in your 'Sweave_animation' demo, in the Lyx-Beamer? The 'Sweave_ani_demo-Newton.pdf' has to be 'manually' copied to the Beamer's temp directory in order to make Lyx-Beamer no complain. It is because Beamer does not know where the 'Sweave_ani_demo-Newton.pdf is.
Unfortunately the LaTeX package animate and its macro animategraphics{} do not understand the command definput@path{{/path/to/your/images//}}, which is generated by LyX to ensure LaTeX can find the image files. Other LaTeX macros like includegraphics{} can find the graphics under the directory of the lyx document.
It's a little bit annoying but I have a solution to tackle this problem. Since you seem to be using the animation package, there is an argument 'full.path' in saveLatex() that you may want to use: set full.path = TRUE so that this function will write the full path of animations in the LaTeX document. Then there is no reason that animate cannot find the graphics.
This is not an elegant solution. I cooked up a demo here:
http://gitorious.org/yihui/lyx-sweave/blobs/master/demo/animation-LyX-Sweave-demo.lyx
Output is like:
http://gitorious.org/yihui/lyx-sweave/blobs/master/demo/animation-LyX-Sweave-demo.pdf
Originally posted on 2011-02-07 07:28:22
Guest *Shelly* @ 2011-02-07 09:45:49 originally posted:
There is an interesting problem I have here.
When 'full.path = FALSE', I got the error message as follows as I expected:
Errors:
pdfTex Error
Description:
pdflatex (file Rfig-animation-demo.pdf):cannot find image file
When 'full.path=TRUE', I got the error message as follows as I have no clues,
Errors:
Undefined control sequence.
Undefined control sequence.
Undefined control sequence.
Undefined control sequence.
Undefined control sequence.
Description:
...5}{C:TEMPRDataRfig-animation-demo}{}{}
The control sequence at the end of the top line
of your error message was never def'ed. If you have
misspelled it (e.g., hobx'), type I' and the correct
spelling (e.g., `Ihbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
The only reason I guess because I am using animation_2.0-2 now, I might later update to animation_2.0-3 as your sessionInfo() shows, then see whether it is the cause or not.
No, it has nothing to do with the version of the animation package. Once again, Microsoft Windows needs special love and care... Unfortunately this is a very dirty issue for LaTeX, especially when the file path contains spaces.
I see your file path does not contain spaces, which is good. I can fix the problem in the animation package (just replace `` with / in the path). Remember never to use spaces anywhere.
The fix will come out in 2.0-3.
Originally posted on 2011-02-07 11:50:33
Guest *Shelly* @ 2011-02-08 04:26:38 originally posted:
I recompiled my animation 2.0-2 with updated saveLatex.R - it runs error-freely on my Windows environment.
Your solution is working perfectly, thanks!
Since you're working on 2.0-3, there is one thing which is not related to animation package, but could be related to Sweave or Latex and might be worth a bit your attention and my curiosity.
For easy understanding, I use demo('Sweave_animation') as an example, the published R source code in PDF has 'NO' highlights in colors, just in black. We all know the PDF is generated by the following process -
Sweave('Sweave_animation.Rnw')
tools::texi2dvi('Sweave_animation.tex',pdf=TRUE)
If similar Latex code is directly applied to the Lyx, the published R source code in PDF has hightlights in colors as we expect.
Good question. This is why I have been advertising for the pgfSweave package :) I'm never satisfied with R's default Sweave functionality, and pgfSweave has a lot of advantages over Sweave. Syntax highlighting is the benefit from the R package highlight, which is used by pgfSweave to highlight R code by default.
Originally posted on 2011-02-08 05:14:44
Hi, I asked the author of the animate package yesterday, and I realized this should not be a problem if you use the latest version of that package, which was published on 2010/09/28. If you run kpsewhich animate.sty in the command window and find out the path to this package, you may open the package and see its publishing date like this:
def@anim@version{2010/09/28}
If your package is older than this, you need to update. I'm not sure if you are using MikTeX -- if so, you can find the update menu from the Start menu.
Then you won't need to set full.path=TRUE, but you still need to guarantee that there are no spaces in your file path.
Originally posted on 2011-02-09 07:30:05
Guest *Shelly* @ 2011-02-10 01:26:09 originally posted:
Yes, you are right. My 'animate.sty' with MikTex 2.8 shows
def@anim@version{2010/08/31}
After I update it by the 'animate.sty' from your animation package/library, I don't need to set full.path=TRUE. Of course, there is no space in the path.
Your solution is confirmed to work perfectly, thanks!
It's great to know that we can get rid of the ugly solution full.path=TRUE :) Thanks!
Originally posted on 2011-02-10 02:15:17
Guest *pakmanaz* @ 2011-02-16 06:21:59 originally posted:
Yihui,
First, thanks so much for the instructions and demo. I have tried many guides but seem to always get stuck, but this one so far has been the easiest.
Unfortunately, I have a problem with my installation. I am running this with LyX 1.6 and R 2.12 on Windows. I didn't receive any errors when I ran your source command in R, and then I reconfigured LyX. All seemed to be fine. However, when I try anything in the sweave no web class, even the demos, I always get the error when I try to make a PDF:
Cannot convert file:
An error occurred whilst running Rweave "animation-LyX-Sweave-demo.Rnw"
Did I miss a step and forget to install something?
Thanks again.
The error message does not seem to be correct; it should be something like this: Rscript "path/to/lyx-sweave-exec.R" UTF-8 "path/to/animation-LyX-Sweave-demo.Rnw" ...
Did you install the animation package in R (install.packages('animation')) as well as the animate package in LaTeX (mpm --install animate)?
Originally posted on 2011-02-16 09:46:34
Guest *pakmanaz* @ 2011-02-16 22:14:14 originally posted:
Thanks for your reply! I did install both of them, and ran your script for the remaining packages. Could it be a problem that I am using 64-bit Windows 7 and the R directory is in Program Files and LyX directory is in Program Files x86?
I don't think the path of the software matters. Can you double check the error message? As I said, the error message should not be Rweave "animation-LyX-Sweave-demo.Rnw".
The only reason I can think of is that you used other methods to modify your preferences file, and my auto-config script is unable to recognize the modification. I suggest that you remove your preferences file first; or at least you need to remove the Sweave converter (menu Tools --> Preferences --> Converter: remove all the Sweave-related converter and run my script again)
I have tested this script for many times under Windows 7.
Originally posted on 2011-02-16 23:12:16
Guest *pakmanaz* @ 2011-02-17 01:52:16 originally posted:
Thanks so much! It worked like a charm. I must have messed up the preferences file earlier when I was trying to follow a different guide. I should have checked and erased the previous modifications... This time it worked perfectly. Thanks again, and sorry for wasting your time! The output is really beautiful, can't wait to start using it for my assignments!!
Guest *pakmanaz* @ 2011-02-17 02:24:22 originally posted:
Sorry to come again, but there now seems to be a different problem. The minimalist file works fine, but whenever I try a file of my own or even your LyX-pgfSweave-demo-Yihui-Xie , I first get the error window: An error occurred whilst running Rscript ".../AppData/Roaming/LyX16/scripts" and then the log file has the following errors:
Error: chunk 2 (label=data-summary)
Error in file(file, "rt") : cannot open the connection
In addition: There were 19 warnings (use warnings() to see them)
Error during wrapup: Take a look at the error log file: C:/Users/AZ/AppData/Local/Temp/lyx_tmpdir.Hp1812/lyx_tmpbuf0/LyX-pgfSweave-demo-Yihui-Xie.Rnw.log
Execution halted
How come it only works for the minimalist version?
Sorry for bugging you again! Thanks!!
This error message is good news for me. It says you have no problem with the configuration now -- all the errors are coming from R, which are much easier to debug.
It's possible to run into errors when running my demo, because in this demo, R has to read the dataset from a website, which might not be available by the time you were compiling the LyX document. The error message told you that the 2nd chunk was in trouble, so you can simply copy and paste the code in that chunk into R and see if it can run correctly.
I'm curious about the warning messages. They might be important to help us debug the R code, so I updated the configuration to print the warnings in case of errors. You may run the configuration script again, then see what these warnings are.
Originally posted on 2011-02-17 03:56:53
Guest *pakmanaz* @ 2011-02-17 04:38:45 originally posted:
It seems to be working this time. I simply reran the configuration, and I didn't get any warnings. Even the document I created seems to work fine. I will come back if I find any warnings. Thanks again!
Guest *avenin* @ 2011-02-28 06:34:21 originally posted:
Does it work on Mac os X ????
Guest *pezzacolori* @ 2011-03-09 18:03:18 originally posted:
I run your source file, but I have problems with the working directoy.
getwd() in my r code returns the temporary directoy of lyx ...:
[1] "/tmp/lyx_tmpdir.T10592/lyx_tmpbuf0"
so that I can not really read from a csv file where the lyx document is, wihtout setting the working directory expressely (so my file is not reproducible when moved to another path).
aM i DOING SOMETHING WRONG?
Thanks,
Boris
This should not be the case, because I have already set the working directory to be the directory which contains your .lyx file (http://gitorious.org/yihui/lyx-sweave/blobs/master/lyx-sweave-exec.R#line19). Can you re-run the configuration script and confirm getwd() is the temp directory?
source('http://gitorious.org/yihui/lyx-sweave/blobs/raw/master/lyx-sweave-config.R')
Originally posted on 2011-03-10 09:16:44
Guest *pezzacolori* @ 2011-03-10 22:33:51 originally posted:
Now it works! Maybe the cause could be that I firstly run your code as root?
Anyway now it works. Many thanks.
I have another problem, probably simply due to my little experienc ewith Lyx and Latex. I work on Ubunutu linux 9.10.
If I open your demo1 with your demo 1 file in Lyx 1.6.9, the notation external=TRUE,pdf=FALSE,eps=FALSE
appears as UNDEFINED, and compilation fails (LaTeX error: Command Schunck already defined).
If I remove the lines in the Document>Settings>LaTeX preamble
usepackage[nogin]{Sweave}
usepackage{tikz})
then it compiles ... but writes in the document also the
external=TRUE,pdf=FALSE,eps=FALSE
sentence.
What could be the problem?
Thanks,
Boris
Boris
You can simply delete the UNDEFINED sentence. These options control the behavior of Sweave and they are not absolutely required. If they appear as UNDEFINED, you must have a problem when running the config script (literate-scrap.inc was not correctly copied to the place where it should be).
The preamble should be removed too. I have corrected the demo files.
Originally posted on 2011-03-11 07:42:45
Guest *Subramanian* @ 2011-03-10 19:44:46 originally posted:
Hi Xie
First, thanks for your great posts.
i tried Lyx2.0 beta. i am able to work and produce output with sweave module i can see that lyx 2.0 can sweave "out of the box" as they said if we just choose sweave in the document > settings > modules. But i am not able to use pgfsweave with Lyx 2.0 beta. How do i configure it? Can you please guide me.
You may try source('http://gitorious.org/yihui/lyx2-sweave/blobs/raw/master/lyx-sweave-config.R'), but I cannot guarantee that it will work under Windows. I've been using LyX 2 beta under Ubuntu and it works well. I will take a closer look when LyX 2.0 is formally released.
Originally posted on 2011-03-11 07:23:32
Guest *Subramanian* @ 2011-03-11 09:27:45 originally posted:
Hi Yihui
Thanks for the reply.
Versions: R 2.12.1, Lyx 2.0 Beta. OS: Windows 7 (32).
i tried your suggestion. i downloaded the R-file (in http://gitorious.org/yihui/lyx-sweave/blobs/raw/lyx2/lyx-sweave-config.R) to my disk and ran the code in R. It downloaded packages and configured Lyx. i restarted Lyx and tried your demo in lyx (http://gitorious.org/yihui/lyx-sweave/blobs/raw/lyx2/demo/pgfSweave-in-LyX-2.0.lyx) It dint run- May be i could help you with the exact error message:
An error occured while running:
R script: "C:/Users/SS/Appdata/Roaming/lyx16/scripts/lyx-sweave-exec.r" "UTF8" "pgfsweave" "C:/Users/SS/Appdata/Local/Temp/lyx_tmpdir.gq3652/lyx_tmpbuf2/" "demo_pgfSweave-in-LyX-2.0.Rnw"
i went to the directory of the error msg In .../Roaming/lyx16/scripts/ i found the lyx-sweave-exec.r file. But in .../Appdata/Local/Temp/ but i dint find a dir by name lyx_tmpdir.gq3652
Any clues?.
Guest *Subramanian* @ 2011-03-11 15:12:59 originally posted:
I guess the problem is here:
in R my current dir is "C:/Users/SS/Documents"
if set the tempdir with setwd(tempdir()) and find out the dir i get
"C:/Users/SS/AppData/Local/Temp/Rtmp2HBPPd"
But while compiling in Lyx, the dir it is looking at is the lyx_tmpdir...
First, the link for the config script should be http://gitorious.org/yihui/lyx2-sweave/blobs/raw/master/lyx-sweave-config.R; the URL you used was wrong.
Second, you should avoid setwd() in Sweave; this will confuse R and LyX. In your case, the working directory for R was C:/Users/SS/Documents
As I said before, currently I am unable to guarantee that my configuration works for Windows and LyX 2 beta version. I have been testing under Linux.
Originally posted on 2011-03-12 10:03:37
Guest *Subramanian* @ 2011-03-10 19:45:55 originally posted:
By the way, forgot to mention, i'm working on Windows 7
Guest *Subramanian* @ 2011-03-14 10:16:30 originally posted:
Thank you Xie.
i am able to get pdf output of your demo file (pgfsweave demo in Lyx 2.0) if i copy all the config files into C:Program FilesMiKTeX 2.9texlatex and C:Program FilesMiKTeX 2.9bibtex and C:Program FilesLyX 2.0beta4Resourceslayouts. However i am not able to get the output by running the config script (http://gitorious.org/yihui/lyx2-sweave/blobs/raw/master/lyx-sweave-config.R) in R. I get the r script error.
I wonder why because as i understand the only difference between the two is that the former copies into the Program files/Miktex... while the latter puts them in the C:/Users/Appdata...
Another question, i have not been able to get the r codes in color in the pdf output despite saying highlight=TRUE in the first line <>== of the code chunk. Is there anything else that i have to add in the preamble of the document?
Guest *Frode Severin Hatlevik* @ 2011-03-16 11:38:30 originally posted:
Please forgive me. I am a LyX and R beginner, and I found that your script did not work quite as intended. For instance I was unable to use your setup with IPSUR.lyx after using your script.
Now that LyX 2.0 is comming up I see a good opportunity to try to incorportate pgfSweave into LyX. I have no clue as to the details in this, but I have some suggestions on where to start, though. Note that Diego Queiroz has provided unofficial test binaries for LyX 2.0 RC1 for Windows, and posted links to them on the lyx-user mailing list. I have not tried them myself, and cannot vouch for them.
For using Sweave with LyX I have had great luck mixing the instructons as published by Jeff Laake http://wiki.lyx.org/uploads/LaTeX/SweaveR/lyx_with_r_and_sweave_instructions.pdf with the instructions in Gregor Gorjanc's Rnews article at http://www.r-project.org/doc/Rnews/Rnews_2008-1.pdf.
The key to this success was to install all the software required as instructed by Jeff Laake, and setting up LyX for use with Sweave according to the insructions in the paragraph
Using Sweave with LyX => LyX Customisation => "Install"
in Gregor Gorjanc's article.
The folder containing the R executable also needs to be in PATH.
This also worked for a system-wide LyX customisation.
It even works if I include the 'share/texmf' forlder from the R installation in the MiKTeX search path system wide, and only put 'noweb.sty' in the systemwide local texmf directory.
I am using LyX 1.6.9, MiKTeX 2.9 and R 1.12.2 on Windows 7 64 bit.
Is this a viable approach to using pgfSewave with LyX too, i.e. creating a file 'literate-pgfSweave.layout, or something similar, and put the needed configurations there?
I was advised on the lyx-users mailing list that pgfSweave could possibly be incoroprated into LyX using a module and an R script. Might this be another option for integrating pgfSweve with LyX?
Regards
;)Frode
Hi Frode,
Thanks for your information! The main purpose of my configuration script was to get rid of these "step 1 to step n" -- they are too tedious. I have never tried IPSUR.lyx and I don't know how the author configured his LyX and R. With LyX 2.0, Sweave has become a module and can be used with any kind of documents, i.e. we no longer need the layout files such as literate-pgfSweave.layout.
I think it is enough for us to have Sweave support in LyX; I'm not sure if we really need to integrate a pgfSweave module as well. The problem is, there are too much flexibility in using Sweave with LyX, e.g. I'm not satisfied with the R script shipped with LyX.
At the moment, I can only offer help to Linux users and I've been working happily with LyX 2.0 beta versions. I'll take a look in my Windows 7 after the final release of LyX 2.0.
Originally posted on 2011-03-17 06:10:30
Guest *Subramanian* @ 2011-03-24 10:39:36 originally posted:
Yihui
Have you looked at Rstudio? www.rstudio.org. It allows one-click pdf generation of a Sweave document.
Can you let me know how to configure pgfsweave with rstudio? That will be great.
Yes, I have. That's a great feature. RStudio has its own script to run Sweave, and it seems to be hidden somewhere. I don't know. Theoretically it should be easy to make RStudio to work with pgfSweave; it is only a matter of changing Sweave() to pgfSweave(). You need to talk to the developers; I don't want to hack at this part purely from R (it is possible but nasty).
Originally posted on 2011-03-25 08:05:40
Guest *tim* @ 2011-04-08 21:03:37 originally posted:
Since you've been using Lyx 2.0rc in Ubuntu, would you mind sharing how you set up pgfSweave? I have Sweave set up and running great, but sometimes the documents take a long time to compile. I would love to be able to use pgfSweave, but the errors are quite opaque. I have PGF 2.1.0 installed, and pgfSweave apparently works fine from R, just not from LyX.
I'd be delighted to make a donation in exchange for your time, of course. (Name your price!)
I do have an automatic configuration script for LyX 2.0rc available, but I don't recommend you to try it at the moment. For one thing, pgfSweave has dramatically improved its approach of caching graphics and I have not fully tested the new features; for the other, I think I will be able to integrate pgfSweave into LyX 2.0 directly, so no manual configuration is required in the future. I will clean up my script during the weekend and submit to one of the developers of LyX; hopefully it will appear in the final release of LyX 2.0.
Donation is really optional. :)
Originally posted on 2011-04-09 09:15:49
Guest *tim* @ 2011-04-12 04:08:20 originally posted:
Option exercised. Most of the demons in PGFsweave exorcised (for example, when using Laura Dietz' indcredibly convenient boilerplate notation macros for graphical models). However, with LyX, it's still a pain in my aissss. What I tried doing was replacing lyxsweave.R with a script 'lyxpgfsweave.R' that attempts to run pgfSweave instaed. This... did not work. If you have any suggestions, I would sure as hell be willing to pursue them. Thanks again for turning me on to pgfSweave (and LyX, for that matter -- I donated their webserver to them something like 10 years ago, and now I'm using the program to write my dissertation. Karma much?)
Guest *Michael* @ 2011-04-15 12:31:54 originally posted:
Yihui,
I was referred to your "Beautiful Dynamic Statistical Reports with pgfSweave" to help me with inserting mathematical structures into my R plot that are not included among the plotmath options. For example I want to have an underbrace, such as one would get in a LaTeX document using the underbrace{} command. Or I want to use mathcal{} to or mathbb{} to alter the font of a letter. The example you give looks like it should be just what I need. I installed pgfSweave in R, and use
library(pgfSweave)
to make it available. But if I enter the sample R commands you provided I do not get what you get. R simply prints the LaTeX code on the plot without converting it. Clearly I have to do something more, but I cannot find any instructions to help me. My impression is that pgfSweave is designed for producing LaTeX documents, not for producing R plots. It also seems that LyX is involved here, but I don't know how. Note that I don't know anything about LyX, and I am a statistician, not a computer scientist.
Thanks for any guidance you can provide me.
Michael
Hi Michael,
Sorry for the late reply. The workhorse for the pgfSweave package is the tikzDevice package, so you do not have to use pgfSweave to produce a plot containing math formulas. You can take a look at the documentation ?tikz in the tikzDevice package; I've cooked up a simple example according to your description here: http://yihui.name/en/?p=719
Originally posted on 2011-05-01 07:30:47
Guest *Giuseppe* @ 2011-05-03 03:43:48 originally posted:
Have you perfected your script for LyX 2.0? I would be very curious to try it.
Thanks! I have almost done. There are still a few problems to solve for multi-byte documents with xelatex. I will announce a working solution for LyX 2.0 separately when I'm completely done. BTW, I don't think I will be able to make it into LyX 2.0 because the version 2.0 has been frozen; probably 2.0.1 can have full support for pgfSweave.
Originally posted on 2011-05-03 08:24:43
Guest *Giuseppe* @ 2011-05-16 14:47:00 originally posted:
Thanks. I will be waiting.
Guest *cristiann* @ 2011-05-03 13:27:04 originally posted:
I've used your script (and suggestions) and briefly ... they work... :)
Some questions (actually, more like a request for less dirty solutions...)
I'm always disappointed by the fact that TeXLive in Ubuntu is never up-to-date. Therefore I just download the huge ISO image and install TeXLive manually; in this way, I can use the command tlmgr update --all to keep it up-to-date. You know, tlmgr does not exist if you install by apt-get install texlive.
I don't switch between Windows and Linux very often, so I have not had such bad luck with things being messed up. I have never tried local layouts either. Sorry.
Originally posted on 2011-05-04 00:53:11
访客 *Honglang Wang* @ 2011-05-21 10:19:36 写道:
为什么我的那个setting 里面没有sweave noweb这一项的哈
这个默认是没有的,必须要按我文中的步骤配置之后才有。不过现在LyX 2.0已经出来了,本文也已经过时了,LyX自带对Sweave的支持,只是不太完善,我已经提交了我的补丁,什么时候能被采纳还未知。
——原帖发布于 2011-05-21 22:35:48
访客 *Honglang Wang* @ 2011-05-22 01:11:40 写道:
我就是按照你的步骤装的,还是没有。我的LyX就是2.0的,R也是最新的,还有MikTex2.9。但还是没有,不知道怎么回事
我说了本文对LyX 2.0来说已经过时了(所以请忽略本文),我已经向LyX开发者提交了补丁,但不知道什么时候能被采纳,如果能被采纳的话,下一个版本的LyX就不需要任何配置了。
在目前的LyX 2.0中,你可以凑合着用Sweave,但使用方法不是选择Layout,而是在任意Layout的文件中加入Sweave模块(module),只要包含Sweave模块,这个文档就可以调用R编译了。当前的Sweave模块很不完善,估计你用的时候还会遇到很多问题。
——原帖发布于 2011-05-22 22:59:30
Guest *René* @ 2011-05-23 22:34:34 originally posted:
Is there a way to run pgfSwaeve within a template like apa.lyx?
thanks René
At the moment, no. In the future, maybe yes. I have rewritten a manual for Sweave and added a manual for pgfSweave in LyX, but I did not manage to finish them before LyX 2.0 was released, so ideally they will appear in LyX 2.0.1 -- I'm not quite sure. Currently my patches have not been applied yet. If you know how to build LyX from source, I can give you more hints. It's not hard under Linux, but can be extremely time-consuming under Windows.
Originally posted on 2011-05-23 22:50:05
Guest *René* @ 2011-05-23 23:34:49 originally posted:
tjanks for the fast replay. Ans yeah if it is not hard ,,, (at least I can try it) so I would appreciate your hints. Im currently on Ubuntu Lucid.
René
Guest *Giuseppe* @ 2011-05-24 22:06:21 originally posted:
I wouldn't mind to test it too. The only thing between me and lyx is pgfsweave...I use it 99% of the time.
So, please, let me know how I can help.
Thanks, Rene and Giuseppe. Since it seems several people are interested in it, I will write a new blog post about it soon. Basically you just check out the source from SVN, and apply the patch here: http://www.lyx.org/trac/ticket/7555 Then see if you can run the two examples (PDF output has been provided there for Sweave and pgfSweave respectively).
Originally posted on 2011-05-25 07:35:14
Guest *human mathematics* @ 2011-09-09 01:49:00 originally posted:
Honestly this is more like getting started in half an hour than 1 minute.
You are right. It used to take 1 minute but it is not quite true now. Lots of changes have taken place in LyX since then. I have put a warning in the beginning of this post, and I do not recommend people to use the approach described in this post any more. I have not managed to add full support of pgfSweave in LyX yet.
Originally posted on 2011-09-09 05:32:17
Guest *human mathematics* @ 2011-09-09 21:08:07 originally posted:
A-ha. Well the other post has a warning as well. I'm not sure which set of instructions to follow so I'm trying both (older first under the assumption it would be more stable).
But I'm getting errors like 1, 2, 3. Latest is on following the second set of instructions, after deleting ~/.lyx and reconfiguring, Ctrl+D is disabled and the only option to View is LyXHTML.
I was also unclear until recently that pgf and pgfSweave are distinct; I thought the former was shorthand for the latter. (matters with version numbers)
Thanks for responding.
pgf is a LaTeX package; pgfSweave is an R package. Judging from your error messages, it is likely that the pgf package is missing.
I believe the last part of this post (http://yihui.name/en/2011/05/sweave-and-pgfsweave-in-lyx-2-0-x-experimental/) has explained all the magic behind the scene. All you need are: a format, a converter (with an R script) and a module.
Currently I somehow regret putting these preliminary work online; beginners can be easily discouraged due to lack of detailed explanation and changes in LyX itself.
Originally posted on 2011-09-10 06:22:25
Guest *human mathematics* @ 2011-09-09 05:00:56 originally posted:
I also like the
noginoption forSweave.styto be the default inpgfSweave
How does one set nogin to be the default?
This is done in the module definition in layouts/sweave.module. If you want to do it manually in a specific LyX document, you can go to Document --> Settings, you see a text field named Class options; just write nogin there.
Originally posted on 2011-09-09 05:34:40
Guest *human mathematics* @ 2011-09-09 21:12:49 originally posted:
Thanks for the response. Is this still necessary in LyX 2.0? The other post says that everything comes pre-configured.
Yes. Only noae is the default option; you have to manually set nogin by yourself (as described above).
Originally posted on 2011-09-10 05:08:47
Guest *human mathematics* @ 2011-09-11 07:09:45 originally posted:
Wow, this was so difficult. One thing that everybody with Ubuntu, at least, needs to do, is get a new Tex Live distribution. The texlive-full package in Synaptic is a couple years out of date. I would recommend that anyone trying to get LyX, Sweave, pgf, and so on to work first check with sudo tlmgr update --all and, if that fails (for example you don't have tlmgr) then get a newer TeX from: http://www.tug.org/texlive/acquire-netinstall.html.
Guest *Paul Johnson* @ 2011-10-29 23:48:42 originally posted:
Greetings. I've been using LyX with Sweave a long time and just stumbled across your projects while studying roxygenize2. I've been testing your converter code with LyX 2.0 on Debian linux and the demo documents you offer turn out fine, except the figures are missing. In the pdf output, it says:
[[ I MAGE D ISCARDED D UE T O ‘/tikz/external/mode=list and make’ ]]
I am now tracing my way through a complicated web of blogs and web pages about pgfsweave and externalization. This is almost like work :) In case you have a solution, I would be glad to know.
pj
I think I understand your situation; this is just because pgfSweave relies on the tikz externalization library, so the document has to be compiled at least twice: in the first time, LaTeX ignores the tikz figures in the main document but it will compile them to PDF one by one; in the second time, LaTeX will see the tikz plots have been compiled, so it just loads the PDF. This is what I understand as tikz externalization.
To deal with LyX is tricky, and I do not want to share with you the gory details behind the scene, although I have figured out how to work with this situation a long while ago. Instead I recommend you to be prepared for my new package knitr, which comes to solve most common headaches that we had in the past. I'm busy documenting it these days, and you can take a quick look at the website http://yihui.github.com/knitr as well as an incomplete manual https://github.com/downloads/yihui/knitr/knitr-manual.pdf
I have given up the idea to support pgfSweave in LyX. I have spent too much time on this in the past, feeling more and more hopeless, and ended up rewriting another engine as an alternative to Sweave. Hopefully it will integrate with LyX much better than Sweave or pgfSweave (at least I wrote the above manual in LyX with knitr). I'm not sure if it is a good time to try it right now; I'll send an annoucement for the beta version when I'm done.
Originally posted on 2011-10-30 01:41:46
Guest *Paul Johnson* @ 2011-10-30 09:08:00 originally posted:
Thanks. That's very interesting. I can read your knitr-manual.pdf, but the effort to load the first knitr link you provide results in "unable to connect". Before I forget, can I share 2 ideas?
I'm concerned you don't implement "split" in knitr. That's a pretty important feature for me because it keeps copies of all the files in a separate directory. The publisher will take a LaTeX file, but will not run R or Sweave. My plain to work around that is using LyX branches. The R code chunks all look like this:
This is inside an R branch:
<>=
plot(...)
@
and then later, outside the R branch
includegraphics{plots/t-mycode10}
So the branch that has the R code runs, and saves the files, and then when I turn off the R branch, the document still compiles. If you don't implement split, that approach will fail miserably.
I wonder if you are still using Verbatim for Sinput and Soutput? Lately, I quit using Sweave.sty and use Sweavel.sty from Frank Harrell's web site. The main benefit there is that instead of Verbatim for code chunks, it uses listings. That gives some color coding options and more beautiful symbols, but for me the most important benefit is that I can get pleasant looking line-wrap on long lines.
Good luck with your project, it looks very ambitious.
Link fixed (sorry, it should be http instead of https).
I'm still at an early stage, so I'm open to suggestions, and I love to hear what is important to Sweave users and what are not. I will definitely reconsider split.
For Sweave.sty, it has to be abandoned. It is neither beautiful nor easy to use. The default in knitr is to use the framed package (LaTeX) and the highlight package (R). However, you are completely free to customize it. I had listings in mind when I was developing knitr, e.g. the incomplete example at http://yihui.github.com/knitr/objects I will write demos in listings in the future. I have almost finished the core parts of knitr, and it may take me a while to document it.
Originally posted on 2011-10-30 09:37:38
I have added the split option; it is very easy to implement in the current framework. However, you may want to try the cache option in the future; if you cache a chunk, it will be skipped for evaluation but the results are still there (because results are cached too), so you do not lose speed and save the efforts to switch back and forth between branches. If you make a change to the code in the cached chunk, it will be re-calculated and re-cached next time.
Originally posted on 2011-11-01 08:05:50
Guest *Atanu* @ 2012-02-14 12:45:14 originally posted:
I have run your code. It stops running after configuring LYx. When I close LYX an error message appears . Also I cannot find SweaveNoweb in the dropdown box and cannot convert to pdf
Sorry I just moved my blog posts to a new system and the warnings in the first paragraph do not seem to be obvious now. I do not recommend you to read this post any more, since it is very outdated. Please go to http://yihui.name/knitr/demo/lyx/ to see our recent work, which is becoming much neater than the approach described in this post (especially after LyX 2.0.3).
Originally posted on 2012-02-14 21:51:41
Sign in to join the discussion
Sign in with GitHub