4 Replies
Guest *josiekre* @ 2012-02-27 18:57:05 originally posted:
Hi! Per your mention on Twitter, I installed the lastest build of RStudio (Mac version RStudio-0.96.36). I'm finding some inconsistencies and can't figure out why so I thought I'd share with you. I changed the "Compile PDF" preferences to: knitr, pdfLaTeX, and checked everything but "Enable shell escape commands." When I hit the "Compile PDF" button, I get a pdf without any highlighting or tidying (i.e. > and + still appear, messages do not, etc.) and the cache is not created. When I run the same exact file in the console using knit('test.rnw') and texi2pdf('test.tex'), the file has all the specified highlighting, tidying, and cacheing.
I then thought it was maybe something with my test file so I tried running it with your 'knitr-minimal.Rnw' file. The pdf built with the compile button, but a weird output was created. The first page has "> options(replace.assign=TRUE,width=90)" printed at the top with nothing else and the second page is the intended document with unhighlighted, untidy code. Running knit() works but then texi2pdf() from the console fails.
Let me know if you'd like more info or if I've missed something completely obvious. Thanks-- great work!
Thanks for the feedback. Can you see a line require(knitr); knit('knitr-minimal.Rnw') in RStudio when you hit the compile button? Which version of knitr are you using? (see packageVersion('knitr') in R).
Originally posted on 2012-02-27 19:49:02
Guest *josiekre* @ 2012-02-27 23:31:52 originally posted:
packageVersion('knitr')
[1] ‘0.2’
When I hit the compile button with this build, a new tab opens up in the same space as the console that does not have "require(knitr); ... " (Note: This new tab does not occur on the last stable build I was using.) The new tab starts with:
"Writing to file knitr-test.tex
Processing code chunks with options..."
...like it would if it was sweaving. I no longer see the fancy progress bars etc. The opened tab is odd too because it requires that I move the mouse to get to it rather than just see the results in the window I'm working in or keyboard shortcut to them.
Finally, I've switched back to the last stable build for the time being because the editor window wouldn't let me highlight text with the mouse to copy and paste either.
Let me know what else I can provide you with.
Sounds weird. When you specify the weaving engine to be knitr, RStudio should load the knitr package and call knit(). I tried both the Ubuntu and Windows versions of the daily build, and they worked fine. Unfortunately I do not have a Mac to test with.
Originally posted on 2012-02-28 00:40:31
Guest *johnomics* @ 2012-03-07 10:48:01 originally posted:
I have the same problem on a Mac, running RStudio 0.96.45 and knitr 0.3. Although I have knitr selected in the Sweave -> Weave Rnw files using... dropdown box, the Compile PDF button appears to trigger Sweave, not knitr. The .tex output files have usepackage{Sweave}, begin{Schunk} etc etc. If I run knitr from the command line within RStudio, it works.
A simple fix is to specify knitr via a tex command at the top of an Rnw file:
% !Rnw weave = knitr
See here:
http://www.rstudio.org/docs/authoring/rnw_weave?version=0.96.45&mode=desktop
But it looks like knitr isn't quite integrated into RStudio correctly yet, at least not on Macs.
Thanks for the solution. I will report this issue to RStudio developers.
Originally posted on 2012-03-07 20:04:55
Guest *johnomics* @ 2012-03-07 20:07:59 originally posted:
Whoops, forgot to add I reported this to RStudio here:
http://support.rstudio.org/help/discussions/problems/1827-compile-pdf-with-knitr-not-working-on-mac/
Hi, according to RStudio developers, this might help if you are inside an RStudio project: http://www.rstudio.org/docs/authoring/latex_program Also see the reply by @82c9d07618c90a1415c39a06550c728a:disqus below.
Originally posted on 2012-03-08 22:10:47
Guest *johnomics* @ 2012-03-09 09:14:48 originally posted:
The problem is that there is a project-specific Compile PDF option as well as a general Compile PDF option and the project-specific option overrides the general option. If the project-specific option is changed too, all is well. I guess this just affects projects created with Sweave as the default option, ie before knitr integration was introduced. Thanks to Josh Paulson from RStudio, who commented here:
http://support.rstudio.org/help/discussions/problems/1827-compile-pdf-with-knitr-not-working-on-mac
Guest *Dickliang911* @ 2012-06-15 19:03:45 originally posted:
People may use neither rstudio nor lyx, is it possible for you suggest some commands to generate pure latex and .r files like Sweave("file.Rnw") and Strange("file.Rnw") in Sweave?
Thanks!
Use knit() for Sweave(), and purl() for Stangle() after you library(knitr).
Originally posted on 2012-06-15 21:43:50
I never got RStudio to knit pdf properly (using a Mac). I stick to Base R. Here is my knitloop (literally "knitloop.R") that I run on R to compile file.Rnw, which I edit in any editor (Textedit, R, Visual Studio Code).
## knitr loop
setwd("~/Downloads/")
library("knitr")
file_name_part <- "2026_01_09"
knit(paste0(file_name_part, ".Rnw"), output=paste0(file_name_part,"_me_v1.tex"))
system(paste0("/Library/TeX/texbin/pdflatex ~/Downloads/", file_name_part, "_me_v1.tex"))
You can also call knit2pdf():
file_name_part <- "2026_01_09"
knitr::knit2pdf(paste0(file_name_part, ".Rnw"), output = paste0(file_name_part, "_me_v1.tex"))Thank you so much for the suggestion. Unfortunately, I could not get it to work. I am not very good with environment variables, and I do not know how to fix "! /bin/sh: pdflatex: command not found". Thanks for trying to improve my code. I appreciate it.
You are welcome! It seems that /Library/TeX/texbin is not in your PATH. You can add it via:
if (Sys.which('pdflatex') == '')
Sys.setenv(PATH = paste(Sys.getenv('PATH'), '/Library/TeX/texbin'), sep = ':'))This can be put in your ~/.Rprofile so it will be automatically applied every time when R is started.
Alternatively, if you don't have a strong reason to use TeX Live (or MacTeX), you may try my TinyTeX (tinytex::install_tinytex()), which doesn't require you to modify PATH.
I just made a change in the R package {tinytex} so that you won't need to tweak the PATH variable by yourself: rstudio/tinytex@e21398b If you
install.packages('tinytex', repos = c('https://rstudio.r-universe.dev', 'https://cloud.r-project.org'))and restart R, you should be all set. No need to install TinyTeX if you don't want to.
访客 *Junyu* @ 2012-07-07 03:49:34 写道:
Hello,益辉:
请教一个问题,我在Rstudio中创建了一个R Markdown文件。当我输入中文时,click "knit HTML" icon, 中文部分不显示. 我在option中,把default encoding 设为UTF-8。是不是Rmd不能使用中文,还是我的什么setting不对?
File--Save with Encoding重新选UTF8保存一下再试试。Rmd可以用中文。多字节文档在Windows下一直是个麻烦,近期我会到Windows下再好好测试一下。建议你从Github重装一下formatR包:https://github.com/yihui/formatR#readme
——原帖发布于 2012-07-07 04:59:35
访客 *Junyu* @ 2012-07-07 21:22:31 写道:
谢谢。我按照你说的重新装了formatR,并且把文件save with encoding UTF8,还是不行。还有一个问题请教,我现在用R15.0,若是想升级到R15.1,除了下载15.1,然后重装,还有没有什么简单的方法,来update一下?就像update.packages()那样的命令。
我刚历尽千辛万苦找出了一个在Windows下困扰我大半年的bug,现在在Windows殿下那里应该没有编码问题了(不管你用不用UTF8)。请按如下代码更新你的包再测试:
library(devtools)
for (p in c('evaluate', 'formatR', 'knitr')) install_github(p, 'yihui')
在Windows下升级R没有别的办法,只能卸载重装(这不算太麻烦吧)。其实这完全可以通过程序自动实现,只是需要有能力、有精力且有兴趣的志愿者去写这个程序而已(我是三无人员)。
——原帖发布于 2012-07-08 01:23:55
访客 *Junyu Lee* @ 2012-07-08 22:11:31 写道:
还是不行呀。显示不出来中文。若是插入中文,中文以前的英文可以显示;中文以后(包括中文)全都不能显示。其实不用中文也行,先用Rmd做草稿,然后转成Rnw时再加入中文也行,而且漂亮。
看意思是到该dump Windows的时候了。以前用了一两年Ubuntu,不是操作系统不好,而是其它软件不如Windows的多。最简单的,google 拼音。再比如,买个摄像机,带的都是都是Windows下运行的软件。不过一个Win7要100多两银子,实在是坑人呀。Microsoft简直是绑架。
不会吧……我在Win7下测试都没有问题啊。你确定上面三个包都安装成功了吗?
你可以装两个系统啊,我就是同时有Ubuntu和Windows,大部分时间里我都在Ubuntu下工作,实在需要用Windows就切过去用一下。
——原帖发布于 2012-07-09 00:49:31
访客 *Junyu Lee* @ 2012-07-09 03:39:05 写道:
我把
evaluate, formatR, knitr三个包都的delete掉了,copy paste你给的命令,重装的。显示都顺利完成,而且libray里也都有。应该是装上了。可能我的系统不定那里不对劲。前些日子还能compile的Rnw文件,现在又不能生成pdf文件了。只好用Texmaker compile tex文件生成pdf了。总是这出点儿毛病,那儿出点儿毛病。Anyway 谢谢了。我公司还有几个pc,我再试一下。
访客 *dapeng* @ 2013-03-03 20:29:10 写道:
我今天也遇到了你遇到的问题,操作系统是windows 7 64位,折腾了好久也没有解决这个中文支持的问题,直到我换了台windows xp电脑上发现没有任何问题,对比后推测原因可能是Rstudio的版本不同,于是把windows 7上的Rstudio升级到最新版0.97.318,就顺利解决了。
是的,中文问题自从knitr 1.0.5就解决了,现在最新版本的RStudio也完美支持编码。
——原帖发布于 2013-03-03 20:31:01
Guest *xinru chen* @ 2014-10-07 13:42:50 originally posted:
Helllo Yihui,
After finished my Rms file and click compile PDF, it gave me "Unabled to find specified LaTeX program 'pdfLaTeX' on the system path" as a responding and in the meanwhile, Rstudio shows no TeX installation detected. Please install TeX before compiling.
Could you tell how to solve this problem? Thanks in advance.
What is an Rms file? You mean Rnw?
Regarding LaTeX, it depends on which operating system you use: for Windows, MikTeX; Mac OS X, MacTeX; Linux, TeXLive.
Originally posted on 2014-10-12 05:22:20
Sign in to join the discussion
Sign in with GitHub