22 Comments
Guest *Kihoro J. M.* @ 2012-03-03 07:48:17 originally posted:
How do I make zero (0) display a it should instead of a scientific number. Check under Sexpr{k} where k takes value zero (0)
Oh, that is a good test case which I ignored. Sorry. I will fix it soon. yihui/knitr#161 Thanks!
Originally posted on 2012-03-03 16:48:18
It has been fixed in the development version: https://github.com/yihui/knitr
Originally posted on 2012-03-05 03:19:14
Guest *Alan* @ 2012-05-09 11:57:32 originally posted:
Please forgive a naive question, but attempting a very simply example in LyX using the knitr module when I view the result I simply get the R commands set out in pdf - the code did not execute.
This is inserted via Tex code:
<>set.seed(1121)(x=rnorm(20))mean(x);var(x)@i'm clearly doing something wrong - just no idea what!Any suggestions would be appreciated.Alan KellyI'm using the latest version of LyX for Mac and running R 2.15.0 with the latest knitr package installed.sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
locale:
[1] en_IE.UTF-8/en_IE.UTF-8/en_IE.UTF-8/C/en_IE.UTF-8/en_IE.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] knitr_0.5
loaded via a namespace (and not attached):
[1] codetools_0.2-8 digest_0.5.2 evaluate_0.4.2 formatR_0.4 highlight_0.3.1 parser_0.0-14 plyr_1.7.1
[8] Rcpp_0.9.10 stringr_0.6 tools_2.15.0
The syntax is <<>>= (note the equal sign in the end!). If you are a beginner, you may start with my examples: https://github.com/yihui/knitr/tree/master/inst/examples which you can also find under the directory system.file('examples', package = 'knitr')
Originally posted on 2012-05-09 18:56:06
Guest *Alan* @ 2012-05-10 09:31:46 originally posted:
Thanks for prompt reply. I'll study the "knitr-minimal.lyx" example and work from there.
Alan
Guest *Hockeyvic06* @ 2012-09-01 23:58:37 originally posted:
make sure the module is added... it won't stay added for every document.
Guest *Vinod* @ 2012-06-09 18:55:44 originally posted:
I have Windows 7. I have updated the MikTex and Lyx and when I try to read a lyx file in Lyx I get the
message package is missing in my latex installation
prerequisites knitr -->latex
I tried to get the package knitr
It is a zip file has files like demo.ch1 knit.ch etc readme files (all human readable) but do not make sense to me
It is not clear where to put these files.
knitr is an R package, so run install.packages('knitr') in R; then see https://github.com/downloads/yihui/lyx/sweave.pdf
Originally posted on 2012-06-09 19:21:21
Guest *Gfox* @ 2012-07-03 19:43:44 originally posted:
I installed knitr into R and have looked at this document, but still get this message (also on a Win7 machine). I don't see anything in this link (but may well be missing something) that tells me how to respond to this error message from Lyx. Any suggestions?
Guest *Bruce * @ 2012-07-03 22:25:59 originally posted:
I have this issue also on win7 (I have been happily using it on OSX for the past week, and recommended it to gfox...). I need to be able to run this on win7 as well as osx if I'm to use it. At first I thought it might be an issue with LyX 2.04 (just released this week; I had a very old LyX on my pc before), but rolling back to 2.03 gives the same error. I am using MikTeX 2.9... But I assume the knitr->latex converter is part of LyX, not part of LaTeX?
As I replied to @41ac7788f92413dd3561d875e4f69c32:disqus, you need to read the manual https://github.com/downloads/yihui/lyx/sweave.pdf
That is often an indication that LyX cannot find Rscript; you need to let LyX know R's bin path and reconfigure/restart LyX.
Originally posted on 2012-07-04 00:56:50
Please see Section 1 of the manual: https://github.com/downloads/yihui/lyx/sweave.pdf
Originally posted on 2012-07-04 00:57:51
Guest *Gfox* @ 2012-07-04 03:54:49 originally posted:
I've followed these instructions. After installing Lyx 2.0.4, to a Windows 7 machine, I went to Tools:Preferences:Paths and added the location of R (as obtained from R, using R.home('bin'). Then I ran Tools:Reconfigure and then restarted Lyx, and tried to load a lyx file (in fact, one that Bruce sent me). Now Lyx complains (1) that I need to install article.cls (hmm . . . I have a fully working Miktex installation, and article.cls is definitely there), and then (2) still complains that I'm missing knitr ->latex. I'm not sure what else to try to get it to work.
Guest *Bruce * @ 2012-07-04 15:54:42 originally posted:
Sorry, when I first looked at the linked file it did not appear to be about knitr, so I assumed the link was in error.
However as gfox noted, simply adding R to the path did not solve the problem. In the end, as is often the case in Win7, it turned out to be about permissions....
First, installing the development version of knitr (which I recall reading somewhere is required for proper LyX integration) seems to require running R as administrator.
Second, LyX's reconfiguration utility doesn't run properly when running as a user (I eventually found some notes about this from the last time I installed LyX...). One has to:
- Run LyX as an administrator, adding the R path and running the Reconfigure utility. Exit LyX
- For good measure, run LyX again as admin, creating a new document and ensuring that knitr now works. Exit LyX
- Copy the newly generated configuration files from [admin home][application data home]LyX2.0 to [user home][application data home]LyX2.0
a. In a standard desktop configuration, user home will be c:usersusername, and application data home will be appdata or appdataroaming; but if, like me, you are working in a networked file system environment that was first designed under NT, you will have to find your own user home, and application data home may be something like Application Data.
b. The configuration files may just be the .lst files; but I went ahead and copied all the files (not the subdirectories) and that seemed to work. If you upgraded from an earlier version of LyX there may be some other files that appear not to be used any more; I just deleted those and all seems well - Run LyX as user, and hopefully all will be working!
Guest *Gfox* @ 2012-07-04 16:51:40 originally posted:
Just tried Bruce's solution posted above, and it doesn't change anything on my installation (where I'm using all local files) -- I still get the same error messages.
Bruce's solution sounds complicated. Windows is pretty annoying in terms of permissions. Usually I install all my software packages including R and LyX in a different place (e.g. C:/Software or D:/Packages/ where I have full permission to read/write without begging Windows for permission); the default C:/Program Files has all sorts of weird permission problems.
Let's make the last attempt: uninstall R/LyX/MikTeX and reinstall them to another directory; add R's bin path to LyX's preferences of PATH and reconfigure; install knitr.
If this still does not work, we can probably try Skype/screen sharing so that I can better identify the problem.
Originally posted on 2012-07-04 19:32:51
Guest *Gfox* @ 2012-07-05 01:47:06 originally posted:
Thanks, but no thanks -- R and MikTeX work fine on my machines, and I don't think I want to mess with that. I'll just continue to use WinEdt and Sweave (which also work fine on my machines) until these kinks get worked out. I know it takes time to get these sorts of things working in many different settings, and I'm pretty impressed that knitr works so well in so many already - just not mine yet.
Fair enough. It is hard to diagnose technical problems unless I can check your computer by myself :)
WinEdt should be easier to configure than LyX: http://yihui.name/knitr/demo/editors/
Originally posted on 2012-07-05 05:09:12
Guest *Vit* @ 2012-08-16 14:42:00 originally posted:
Hi, I am completely new to both knitr and LyX and my question is probably too stupid - then point me to some resources, please.
How can I mark an R-code paragraph in LyX so that it is recognised and executed in R?
I tried Insert>Custom Insets>S/R expression, but when finally click on View, only a very simple command is executed properly and graphical commands not. Moreover, the commands that were executed are missing in the output and the output is not formatted well - this is probably some Options issue?
example:
when writing in LyX:
some text
1:10
plot(1:10)
some text
with the two lines in the middle marked as S/R expressions, then clicking "View" I get a pdf file where reads:
some text1, 2, 3, 4, 5, 6, 7, 8, 9, 10some text
There must be something simple I am missing or doing wrong.
(working on Windows 7, LyX 2.0.4, knitr 0.7)
Please read: https://github.com/downloads/yihui/lyx/knitr.pdf and see examples under https://github.com/yihui/lyx/tree/master/examples
Originally posted on 2012-08-16 20:52:30
Guest *Vit* @ 2012-08-17 08:47:03 originally posted:
Thanks for your fast reply!
The problem was that I didn't realize I should also read the LyX's Sweawe manual. Now I see the <<>> marks and it works fine.
One more question: I am not able to open your LyX examples (https://github.com/yihui/lyx/tree/master/examples) using LyX, which says e.g. "D:/knitr.lyx is not a readable LyX document". How are these example files intended to be used/opened?
Many thanks for knitr and for your help!
You can download the whole repository as a zip package: https://github.com/yihui/knitr/zipball/master Unzip it and you will find the lyx examples under inst/examples/
Originally posted on 2012-08-19 01:23:34
Guest *Vit* @ 2012-08-30 13:15:59 originally posted:
Many thanks! This works.
Guest *Val* @ 2012-08-17 00:14:58 originally posted:
I'm having some trouble getting knitr to work with Lyx. I have the
current versions of Mac OS X (10.8), MacTex (2012 live), R (2.15.1 -
with knitr library installed), Lyx (2.0.4), and the version of knitr
downloaded (yesterday) from github. I've saved the knitr-minimal.Rnw and
002-minimal.Rnw files to my computer, but they do not open in Lyx. I've
tried to import them to Lyx as knitr (Rnw) files, but get the error:
An error occurred while running:
Rscript --verbose --no-save --no-restore
"/Applications/http://LyX.app/Contents/Resources/scripts/lyxknitr.R"
"/Users/vcav/Desktop/""002-minimal.Rnw"
"/Users/vcav/Desktop/""002-minimal.tex" "/Users/vcav/Desktop/"
From R, I've loaded the knitr library and tried to knit('knitr-minimal.Rnw'), which gives me the error:
Error in eval(expr, envir, enclos) : '...' used in an incorrect context
Warning in parse_params(opts, label = FALSE) :
(*) NOTE: I saw options "..."
are you using the old Sweave syntax? go http://yihui.name/knitr/options
(it is likely that you forgot to quote "character" options)
|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>|
100%
inline R code fragments
Error in eval(expr, envir, enclos) : object 'x' not found
I'm able to run Leisch's sample Sweave files in Lyx without problems, so I know that the R path is set correctly in Lyx.
I'm sorry if this is obvious, but I've run out of things to try. Any suggestions greatly appreciated!
It is not trivial to import Rnw to LyX; in fact this feature does not exist at the moment (although you seemed to have succeeded, the imported lyx document may not be a really valid lyx document).
The best way is to create one by yourself following instructions in https://github.com/downloads/yihui/lyx/knitr.pdf
Or download my lyx examples from https://github.com/yihui/knitr/zipball/master or https://github.com/yihui/lyx/zipball/master
Originally posted on 2012-08-19 01:28:16
Guest *Hockeyvic06* @ 2012-09-01 23:56:27 originally posted:
I am trying to use knitr with lyx and when I follow your example and type
<<>>=
1+1
rnorm(5)
@
I get the error:
An error occurred while running:
Rscript -- verbose -- no-save -- no-restore "C:/Program Files (x86)/LyX20/Resources/scripts/lyxknitr.R"
"C:/.../Temp/lyx_tmpdir.Hp4580/lyx_tmpbuf4/"
"newfile..." (can't see rest of error)
thoughts?
To diagnose the problem, please read https://github.com/downloads/yihui/lyx/sweave.pdf (Section 4)
Originally posted on 2012-09-02 03:23:55
Guest *Philipp_rathjen* @ 2012-11-26 23:26:34 originally posted:
Are you really sure you installed the Knitr package on R and that you are using the newest version of R?
Guest *Jay* @ 2012-11-20 17:09:04 originally posted:
I am trying to use knitr with LYX 2.0.5 on a computer running Windows XP. I can compile and view pdfs of some of the examples you provide but not all. In particular, I cannot get "knitr-minimal.lyx' or 'knitr-manual.lyx' to work. For the 'knitr-minimal.lyx' file, the LaTex log reports the following errror:
! LaTeX Error: Command textquotesingle unavailable in encoding T1.
Any help would be greatly appreciated.
It seems you have solved the problem, and I guess that is probably due to a missing LaTeX package?
Originally posted on 2012-11-20 19:55:53
Guest *Simon-R* @ 2012-11-26 09:37:58 originally posted:
It seems you have solved the problem>
I have the same problem then Jay. Which package do I need? THX
He was using Windows and MikTeX, and he let MikTeX install missing packages on the fly (there is an option which you can find from the start menu). I used the mathpazo package, and other packages such as geometry and hyperref should be common; take a look at the LaTeX preamble and you will see all of them.
Originally posted on 2012-11-26 18:13:15
Guest *Philipp_rathjen* @ 2012-11-26 23:47:37 originally posted:
Hey! Sorry, I'm really new to this. I got knitr installed and now I want to include some plots and summaries from an analysis in R in a paper I'm writing, however I don't wan't ALL the code to show on the PDF. Like where I source it, or certian modifications to the data. What do I do to hide it, even though I need to run it? All the best, and thanks a lot for writing this!!!
use the chunk option echo=FALSE: http://yihui.name/knitr/options
Originally posted on 2012-11-27 00:27:13
Guest *View Alpha* @ 2012-12-04 03:15:31 originally posted:
Hey! I'm trying to start with knitr. It sounds very awesome. Now I'm having some trouble to work with Lyx 2.05 and R 2.15.2 on a windows 2003 server. The rnw file with a plot function works well under Rstudio to produce a pdf. But this pdf could not be reproduced by lyx for there is no R generated figure in the temporary folder which is used by lyx to generate pdf. I have tried to manually include some figure from the toolbar of lyx. That worked well. I tried to simualte the progress descripted in LYX/Resources/scripts/lyxknitr.R. The output shown that generated tex in the temporary folder and generated figure in lyx document folder are well, however there is no copy of the generated figure in the the temporary folder. How could I solve this problem, Thanks!
Guest *View Alpha* @ 2012-12-04 06:57:56 originally posted:
Finally, I found that the missing of VC++ 2008 runtime library made the lyx to do a wrong work. But here, I will still thanks a lot for your effeort !
Guest *Pierre-Olivier* @ 2012-12-13 16:35:11 originally posted:
It works, but I cannot write a french text around. When I try to type using for example a letter like "é" in a title, the compiler said:
File ended while scanning use of title.
<*> nouveau1.tex
*** (job aborted, no legal end found)
Guest *Pierre-Olivier* @ 2012-12-13 17:35:07 originally posted:
My bug is strongly related to: yihui/knitr#230
It seems that it is still a problem, it isn't?
Are you using the latest version of knitr? v0.9
And can you try the UTF-8 encoding? (Document=>Settings)
Originally posted on 2012-12-13 17:39:22
Yes, I think so. LyX 2.0.5 has solved a bug related to this, but I'm not sure if you are using 2.0.5 or not.
Originally posted on 2012-12-13 18:35:51
Guest *Pierre-Olivier* @ 2012-12-13 19:52:37 originally posted:
Yihui, thanks to answer so quickly. I update my software (Lyx 2.0.5, knitr 0.9, R 2.15.2, MacTex 2012) and change the settings to utf-8 encoding. I still get the same error. It works only when I write 'e instead of é in my article title.
can you put a code chunk sessionInfo() in LyX and see what is the locale information in the PDF output?
I do not have problems with é under Ubuntu.
Originally posted on 2012-12-14 01:30:56
Guest *Pierre-Olivier Chasset* @ 2012-12-14 07:55:56 originally posted:
Please, find below the result of sessionInfo():
R version 2.15.2 (2012-10-26)
Platform: i386-apple-darwin9.8.0/i386 (32-bit)
locale:
[1] C
attached base packages:
[1] stats graphics grDevices utils datasets base
other attached packages:
[1] knitr_0.9
loaded via a namespace (and not attached):
[1] digest_0.6.0 evaluate_0.4.3 formatR_0.7 stringr_0.6.2
[5] tools_2.15.2
So that explained the problem: the locale should not be C. It sounds like the LyX bug 7741 was not solved on Mac OS? Can you change your GUI language in Preferences to Default and see if sessionInfo() changes?
Originally posted on 2012-12-14 21:46:27
Guest *Pierre-Olivier Chasset* @ 2012-12-15 21:08:29 originally posted:
So, the LyX GUI language in Preferences was already set to default. So, I try with different languages, but I still get the same error and the locale doesn't change: 'C' for all GUI languages.
Can you post the results of this code chunk in LYX as well?
x = as.list(Sys.getenv())
x = x[grep('^L(C|A)', names(x))]
str(x)
And also the results from a normal R session.
Originally posted on 2012-12-17 03:32:47
Guest *Pierre-Olivier Chasset* @ 2012-12-17 13:55:10 originally posted:
From LyX:
List of 2
$ LANGUAGE: chr ""
$ LC_ALL : chr ""
From a normal R session:
List of 2
$ LANG : chr "fr_FR.UTF-8"
$ LC_CTYPE: chr "fr_FR.UTF-8"
Since I do not have a Mac OS to test with, I suggest you post the question to the public such as the LyX mailing list or StackOverflow: http://stackoverflow.com/questions/tagged/r
Originally posted on 2012-12-17 22:27:03
Guest *Pierre-Olivier Chasset* @ 2012-12-18 09:52:40 originally posted:
Alright. Many thanks for your time and your great work.
Guest *Maxim Kovalenko* @ 2012-12-16 00:18:30 originally posted:
Knitr sounds amazing, but even after reading this thread I cannot make it work. I added my R path to Lyx preferences and reconfigured. Due to this, Lyx stopped complaining about the knitr->latex dependency. Then, however, I try to compile the example document (knitr.lyx), but get the following error:
01:16:31.299: Previewing ...
01:16:31.307: (buffer-view: Ctrl+R)
01:16:31.382: Rscript --verbose --no-save --no-restore "C:/Program Files (x86)/LyX 2.0/Resources/scripts/lyxknitr.R" "C:/tmp/lyx_tmpdir.H16828/lyx_tmpbuf2/""knitr.Rnw" "C:/tmp/lyx_tmpdir.H16828/lyx_tmpbuf2/""knitr.tex" ISO-8859-15 "C:/Users/Username/Desktop/"
01:16:31.446: The system cannot find the path specified.
I have checked the paths manually, the only thing missing is "knitr.tex" file, the rest is well in place. Not sure what to do now.
Thanks for any suggestions,
Maxim
Sorry I have never seen such an error before. Google tells me this:
http://comments.gmane.org/gmane.editors.lyx.general/46329
Perhaps it is a MikTeX problem. I really do not know.
Originally posted on 2012-12-17 03:25:31
Guest *Maxim Kovalenko* @ 2012-12-17 17:24:13 originally posted:
Can I do anything in terms of diagnostics?
You can export the lyx file to Rnw (File=>Export), and run knitr on it in R.
library(knitr)
knit('yourfile.Rnw')
And update LyX and MikTeX if you have not done so.
Originally posted on 2012-12-17 22:09:53
Guest *Maxim Kovalenko* @ 2012-12-18 17:27:57 originally posted:
I have figured it out, maybe the solution will be useful for someone else. It appears that there are two instances of Rscript on my 64-bit Win7. One is the C:Program FilesRR-2.15.2bin, while another is in C:Program FilesRR-2.15.2binx64. Initially I have added the first one to the Lyx Path, and got the error above. Then I changed the Lyx Path to the latter, and it worked. Of course, you need to use the 64-bit program on a 64-bit system (well, at least in this case).
Thanks for your support.
Guest *KIM Musak* @ 2013-11-27 07:30:14 originally posted:
can you be more specific, which one of the many options in 'Paths' in Lyx?
Guest *Jose Luis Cañadas* @ 2013-01-16 20:29:31 originally posted:
An important thing for me. When you have a master lyx file and slave lyx file with R code the chunks names are important, specially for chunks what do figures..
Yes, and I emphasized that in http://yihui.name/knitr/options (chunk labels are supposed to be unique). And you can actually set a different figure prefix for different documents by opts_chunk$set(fig.path = 'the-desired/prefix-').
Originally posted on 2013-01-16 21:48:52
Guest *Maxim Kovalenko* @ 2013-01-27 16:21:19 originally posted:
There are a few packages in R that generate TeX code. For example, the package "stargazer" produces beautiful tables, very useful to automatically combine multiple models in a single table. Normally, you copy the output of the stargaze function (which is LaTeX code) in R console, paste into a (La)TeX editor, and generate the table.
Would it be possible to generate TeX code automatically in Lyx? E.g. by specifying:
<>=
load(mydata)
mymodel <- lm(x~y, data = mydata)
library(stargazer)
stargazer(mymodel) # produces TeX code
@
I tried using a respective chunk in an inserted TeX code field in Lyx, but got the raw Tex code as output, instead of the table. Is there another way to do it? Or perhaps it can be implemented in the future versions of knitr? Thanks for your response.
http://stackoverflow.com/q/14407576/559676
Originally posted on 2013-01-27 19:45:13
Guest *Maxim Kovalenko* @ 2013-01-28 09:17:23 originally posted:
Thank you, that works. One also has to add the option messages = FALSE to suppress the stargazer loading text. I have to tell you, knitr is very exciting, it is a beautiful writing tool.
Guest *Maxim Kovalenko* @ 2013-01-28 09:48:41 originally posted:
When I use this with real data I quite often get the following error:
Error: could not find function ".hasSlot"
This is solved by adding "require(methods)" to the chunk. This package is enabled by default in R, and therefore the code runs in the native R environment, but gives an error in Lyx.
LyX calls Rscript, which does not load methods by default; see ?Rscript in R
Originally posted on 2013-01-28 17:51:31
Guest *KarlP* @ 2013-11-05 22:52:57 originally posted:
How do you force a new page in Lyx output driven by R code in the Lyx document?
Background: I'm using knitr in Lyx to create a long report. I have an R program that generates graphs and tables by looping through some data. At the end of each loop, I want to start a new page.
I tried " print('newpage') " in the code.
Doesn't work. What would?
Guest *KarlP* @ 2013-11-06 05:30:22 originally posted:
answered my own question
"cat" instead of "print" in the above expression does the trick
Guest *Samar Singh* @ 2013-12-06 08:36:47 originally posted:
First, I am really chuffed with Knitr on Lyx. Its great to be able to document and write R at the same time.
Recently I have had a problem with googleVis on Lyx/Knitr. I took the googleVis code from https://code.google.com/p/google-motion-charts-with-r/wiki/GadgetExamples#Motion_Chart
library(googleVis)
Motion=gvisMotionChart(Fruits, idvar="Fruit", timevar="Year", options=list(height=350, width=400))
Display chart
plot(Motion)
Create Google Gadget
cat(createGoogleGadget(Motion), file="motionchart.xml")
This ran successfully in the R terminal. On Lyx I created a knitr chunk starting with:
<<result='asis'>>=
and ending with @.
The identical code was put between them.
The resulting pdf output indicates the following error messages in red.
## Error: could not find function "is"
#Error: object 'Geo' not found
The googleVis documentation says that googleVis should work on knitr if result='asis' is inserted. I am sure I am missing out on something but not quite sure what.
library(methods)
And maybe I'm wrong, but I do not think you can use googleVis in LaTeX/PDF.
Originally posted on 2013-12-16 05:22:27
Guest *Samar Singh* @ 2013-12-16 06:35:46 originally posted:
I have tried the other conversions also with equal lack of success. I am now of the belief that possibly GoogleVis is not compatible wtih Lyx.
It is not that googleVis is not compatible with LyX. It is that LaTeX is not compatible with HTML/JavaScript/Flash. They are completely different.
Originally posted on 2013-12-16 21:20:24
Guest *samar* @ 2013-12-17 01:53:44 originally posted:
I agree. However, Lyx is a pretty high level language so I had quite some time ago requested that it be extended to compile to HTML5. The developers had originally said they would put this in for version 2.0 but it keeps getting pushed back. Can't blame them. They have done an outstanding job with the development of Lyx already and this is no trivial task.
Guest *Samar Singh* @ 2013-12-07 05:49:12 originally posted:
Has anyone had any luck with using knitr with Lyx and googleVis? In my case it does not recognize the <<results='asis'>> as a chunk header. I am using Lyx 2.10beta1 on Ubuntu 13.04
访客 *Young.Tao* @ 2014-01-20 14:14:13 写道:
您好,请问一个关于中文乱码问题。我是mac系统,lyx2.0.6+r3.0.2+knitr1.5+rstudio0.98.490(这几个软件都是最新版本),并安装了adobe的四款字体。但是测试您那篇“妈妈说中文报告也可以用knitr自动生成”时,生成的pdf文件的r代码中的中文显示“<u+5b57><u+7b26>...“,其他中文正常。之后我将https://raw.github.com/yihui/lyx/master/scripts/lyxknitr.R 替换后问题依然(对比了一下,其实lyx2.0.6中就已经是这个lyxknitr.R了)。最后我将lyx复制出latex代码,用rstudio新建一个rnw文件进行测试,则全部正常显示中文,所以我估计是lyx的问题。请问应该如何解决呢?非常感谢!
ctex里面水有点深,我建议用XeLaTeX配合中文字体,编码UTF8,对ctex用nofonts选项:http://yihui.name/cn/2011/05/write-chinese-in-lyx/
——原帖发布于 2014-01-30 07:01:30
访客 *Young.Tao* @ 2014-02-03 03:40:42 写道:
非常感谢您的回复。按照您的提示,我修改了lyx的document settings里的设置,结果和改之前一样,生成的pdf文档中,由knitr生成的那部分内容中的中文依然是乱码,而其他部分中文正常。实在不知道是lyx的问题还是knitr的问题了。
RStudio没问题的话,那就是LyX里面什么地方有问题了,我得看消息日志:View--View Messages
你可以粘贴到pastebin.com
——原帖发布于 2014-02-03 06:23:12
访客 *Young.Tao* @ 2014-02-10 14:16:28 写道:
抱歉pastebin.com打不开,我把完整progress messages传到了
https://skydrive.live.com/?cid=2d4ed58b019b20a4#cid=2D4ED58B019B20A4&id=2D4ED58B019B20A4%21105
其中有一个warning,Warning in native_encode(text) : some characters may not work under the current locale。麻烦您看一下,谢谢。
这个警告信息是一个未修复的bug导致的:http://www.lyx.org/trac/ticket/8537#comment:19 我本以为这个早已经修复了,没想到在Mac底下仍然存在,因为我极少用Mac,所以之前没发现。不过这个警告关系不大,如果你要去掉它的话可以在~/.Rprofile里添加Sys.setlocale(,'en_US.UTF-8'),手工告诉R你的系统语言设置是UTF-8环境。
我测试过中文了,用nofonts选项并自行选择XeLaTeX中文字体(例如宋体),没有问题,能正常显示。
——原帖发布于 2014-02-23 05:50:35
Guest *ouldphart* @ 2014-07-28 15:12:47 originally posted:
Thank you for knitr and the documentation. A few minor comments. When I tried to copy the above cat command for OS X users I found it has an embedded white space between the first single quote and the Sys.setlocale that had to be removed to get everything to work. In a Windows system I could not include plots until I went back and reinstalled LyX with the default working directory matching the default temp directory. I would like to be able to control where the figures and documents are saved but I haven't figured out a work-around yet. I have been happily using knitr + MikTeX for awhile and thought I would try LyX but so far I am quite unhappy with the combination. Thanks for knitr:)
Guest *JeffR* @ 2015-01-22 20:26:56 originally posted:
Hello,
I am trying to run knitr with lyx 2.1.2 in ubuntu 12.04 LTS and am having some issues. When I try to run the example I get the following error:
An error occurred while running:
Rscript --verbose --no-save --no-restore "/usr/share/lyx/scripts/lyxknitr.R"
"/tmp/lyx_tmpdir.CcXpJfwb6159/lyx_tmpbuf0/""sweavetest.Rnw"
"/tmp/lyx_tmpdir.CcXpJfwb6159/lyx_tmpbuf0/""sweavetest.tex" ISO-8859-15
I get the same error when I try to run Sweave. I understand this should not be needed for linux, but I have added:
:/usr/lib/R/bin:/usr/share/R/share/texmf/tex/latex
to my PATH in lyx and this did not fix the problem. I have run Seave in older lyx versions in both linux and mac without any issues, but I am afraid to update my mac lyx just in case I run into the same problem and can't compile my old Sweave documents. Any help would be appreciated.
Thanks,
Jeff
Guest *Paul Rougieux* @ 2015-09-17 09:10:16 originally posted:
Sometimes you want to share lyx documents with co-authors who don't have R and Knitr installed on their computer. Let's say the co-authors want to edit a portion of the document which only contains text and mathematical formulas. They should be able to generate pdf from those part of the document after they have deactivated the knitr module. Unfortunately when the knitr module is de activated, knitr chunk return errors. In order to avoid this, it can be useful to place knitr chunks in Lyx branches and to deactivate those branches. This is an answer to a question I asked on stackoverflow http://stackoverflow.com/a/32622112/2641825
Guest *Iman* @ 2016-04-06 08:35:32 originally posted:
Dear Yihui;
I have recently started using lyx on Mac (i did on windows before) .
The files are compiled nicely, But when I add knitR in my modules the file won't get compiled. If I remove it back, It does get compiled, But of corse the Rcode is not run.
Can you help me find out what the problem is?
Guest *Jeremy burnison* @ 2016-12-27 22:10:24 originally posted:
I am having an issue on Mac as well. I get this error when adding knitr module to my LyX document.
"The module knitr requires a package that is not available in your Latex installation, or a converter you have not installed. LaTex output may not be possible."
Any advice or insight?
Guest *Iman* @ 2016-12-28 07:53:41 originally posted:
Dear Jeremy,
Make sure that you have the package knitr installed in R, and also through document settings ->
Modules in lyx
Guest *Jeremy burnison* @ 2016-12-28 18:30:23 originally posted:
Hi, I did have it installed but I believe the Sys.setlocale had to be correct. I reconfigured lyx several times and it eventually identified the Rnd(knitr) module. Now when I try to compile a pdf or View as is done in the example video I get this Error.
Rscript --verbose --no-save --no-restore $$s/scripts/lyxknitr.R
"/var/folders/mz/09m3h9qj0sb8hgclltgxbc0szm70l9/T/lyx_tmpdir.TGanerR20376/lyx_…
Here's my session info
R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.2
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] knitr_1.15.1
Guest *Thibault Lair* @ 2018-10-27 18:56:26 originally posted:
Dear Yihui,
I am frequent user of Lyx and knitr. I tried today to use the kableExtra but got stuck as the pipe operator does not seem to be supported in the knitr module of Lyx.
The below example fails for me:
<<results =="" 'asis',="" echo="FALSE," warning="FALSE," error="FALSE," message="FALSE">>=
require(knitr)
require(kableExtra)
dt <- mtcars[1:5, 1:6]
print(kable(dt)) # Works
print(kable(dt)
%>% kable_styling(full_width = F)) # Does not work
@
Loading magrittr does not solve the issue.
I would appreciate any help.
Best
T
Sign in to join the discussion
Sign in with GitHub