在过去的几个月里,我一直在 Windows 中使用带有 Lyx (2.1.4) 的 knitr 。最近我转移到了 Ubuntu,为 Lyx 提供了相同的版本。我在使用 Knitr 模块时在编译过程中遇到错误。
1)错误消息的副本(来自消息窗格):
01:00:48.616: Previewing ...
01:00:48.667: Rscript --verbose --no-save --no-restore "/usr/share/lyx/scripts/lyxknitr.R" "/tmp/lyx_tmpdir.MvERGeak1905/lyx_tmpbuf0/""newfile1.Rnw" "/tmp/lyx_tmpdir.MvERGeak1905/lyx_tmpbuf0/""newfile1.tex" ISO-8859-15 "/home/user/"
01:00:48.674: running
01:00:48.681: '/usr/lib/R/bin/R --slave --no-restore --no-save --no-restore --file=/usr/share/lyx/scripts/lyxknitr.R --args /tmp/lyx_tmpdir.MvERGeak1905/lyx_tmpbuf0/newfile1.Rnw /tmp/lyx_tmpdir.MvERGeak1905/lyx_
01:00:48.691: tmpbuf0/newfile1.tex ISO-8859-15'
01:00:48.695:
01:00:50.579:
01:00:50.580:
01:00:50.582: processing file: /tmp/lyx_tmpdir.MvERGeak1905/lyx_tmpbuf0/newfile1.Rnw
01:00:50.631:
|
| | 0%
|
01:00:50.636:
|...................... | 33%
01:00:50.641: ordinary text without R code
01:00:50.644:
01:00:50.648:
|
|........................................... | 67%
01:00:50.652: label: unnamed-chunk-1
01:00:51.025: Quitting from lines 11-12 (/tmp/lyx_tmpdir.MvERGeak1905/lyx_tmpbuf0/newfile1.Rnw)
01:00:51.031: Error in data.frame(..., check.names = FALSE) :
01:00:51.036: arguments imply differing number of rows: 3, 0
01:00:51.040: Calls: knit ... <Anonymous> -> <Anonymous> -> cbind -> cbind -> data.frame
01:00:51.043: In addition: Warning messages:
01:00:51.047: 1: In is.na(res[, 1]) :
01:00:51.052: is.na() applied to non-(list or vector) of type 'NULL'
01:00:51.056: 2: In is.na(res) : is.na() applied to non-(list or vector) of type 'NULL'
01:00:51.060:
01:00:51.065: Execution halted
01:00:53.236: Error while exporting format: PDF (pdflatex)
01:00:58.250: (dialog-toggle progress)
2)转换器定义:
Rscript --verbose --no-save --no-restore $$s/scripts/lyxknitr.R $$p$$i $$p$$o $$e $$r
3)我的代码块是
<<>>=
2+3
@
请注意 .Rnw 文件是在 tmp 文件夹 (lyx_tmpbuf0 ) 中创建的,并且可以被 R studio 成功编译。我也可以使用 lyx 中的 sweave 模块成功编译 pdf。
更新 1: 根据 scottkosty 的建议,我检查了 R 和 RStudio 中的系统环境并发现了一些差异(尽管我不知道它们)。
这是R 的输出:
"COLORTERM" "gnome-terminal"
"COLUMNS" "80"
"DBUS_SESSION_BUS_ADDRESS" "unix:abstract=/tmp/dbus-3muQCK69fQ,guid=e7edee405375ab42e386699a0000002f"
"DEFAULTS_PATH" "/usr/share/gconf/ubuntu-2d.default.path"
"DESKTOP_SESSION" "ubuntu-2d"
"DISPLAY" ":0"
"EDITOR" "vi"
"GDMSESSION" "ubuntu-2d"
"GNOME_DESKTOP_SESSION_ID" "this-is-deprecated"
"GNOME_KEYRING_CONTROL" "/tmp/keyring-m9K6wh"
"GNOME_KEYRING_PID" "1515"
"GPG_AGENT_INFO" "/tmp/keyring-m9K6wh/gpg:0:1"
"GTK_MODULES" "canberra-gtk-module:canberra-gtk-module"
"HOME" "/home/user"
"LANG" "en_IN"
"LANGUAGE" "en_US:en"
"LC_COLLATE" "en_US.UTF-8"
"LC_CTYPE" "en_US.UTF-8"
"LC_MESSAGES" "en_US.UTF-8"
"LD_LIBRARY_PATH" "/usr/lib/R/lib:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/i386/server"
"LINES" "24"
"LN_S" "ln -s"
"LOGNAME" "user"
"MAKE" "make"
"MANDATORY_PATH" "/usr/share/gconf/ubuntu-2d.mandatory.path"
"PAGER" "/usr/bin/pager"
"PATH" "/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
"PWD" "/home/user"
"R_ARCH" ""
"R_BROWSER" "xdg-open"
"R_BZIPCMD" "/bin/bzip2"
"R_DOC_DIR" "/usr/share/R/doc"
"R_GZIPCMD" "/bin/gzip"
"R_HOME" "/usr/lib/R"
"R_INCLUDE_DIR" "/usr/share/R/include"
"R_LIBS_SITE" "/usr/local/lib/R/site-library:/usr/lib/R/site-library:/usr/lib/R/library"
"R_LIBS_USER" "~/R/i686-pc-linux-gnu-library/3.1"
"R_PAPERSIZE" "letter"
"R_PAPERSIZE_USER" "a4"
"R_PDFVIEWER" "/usr/bin/xdg-open"
"R_PLATFORM" "i686-pc-linux-gnu"
"R_PRINTCMD" "/usr/bin/lpr"
"R_RD4PDF" "times,inconsolata,hyper"
"R_SESSION_TMPDIR" "/tmp/Rtmpp31WUY"
"R_SHARE_DIR" "/usr/share/R/share"
"R_SYSTEM_ABI" "linux,gcc,gxx,gfortran,?"
"R_TEXI2DVICMD" "/usr/bin/texi2dvi"
"R_UNZIPCMD" "/usr/bin/unzip"
"R_ZIPCMD" "/usr/bin/zip"
"SED" "/bin/sed"
"SESSION_MANAGER" "local/akd-HP-Mini-110-4100:@/tmp/.ICE-unix/1526,unix/akd-HP-Mini-110-4100:/tmp/.ICE-unix/1526"
"SHELL" "/bin/bash"
"SHLVL" "0"
"SSH_AGENT_PID" "1563"
"SSH_AUTH_SOCK" "/tmp/keyring-m9K6wh/ssh"
"TAR" "/bin/tar"
"TERM" "xterm"
"UBUNTU_MENUPROXY" "libappmenu.so"
"USER" "user"
"WINDOWID" "67108870"
"XAUTHORITY" "/home/user/.Xauthority"
"XDG_CONFIG_DIRS" "/etc/xdg/xdg-ubuntu-2d:/etc/xdg"
"XDG_CURRENT_DESKTOP" "Unity"
"XDG_DATA_DIRS" "/usr/share/ubuntu-2d:/usr/share/gnome:/usr/local/share/:/usr/share/"
"XDG_SEAT_PATH" "/org/freedesktop/DisplayManager/Seat0"
"XDG_SESSION_COOKIE" "c143c6cb80cfe9614354b2ab0000000d-1453572539.964572-1541574946"
"XDG_SESSION_PATH" "/org/freedesktop/DisplayManager/Session0"
这是RStudio 的输出:
"DBUS_SESSION_BUS_ADDRESS" "unix:abstract=/tmp/dbus-3muQCK69fQ,guid=e7edee405375ab42e386699a0000002f"
"DEFAULTS_PATH" "/usr/share/gconf/ubuntu-2d.default.path"
"DESKTOP_SESSION" "ubuntu-2d"
"DISPLAY" ":0"
"EDITOR" "vi"
"GDMSESSION" "ubuntu-2d"
"GIO_LAUNCHED_DESKTOP_FILE" "/usr/share/applications/rstudio.desktop"
"GIO_LAUNCHED_DESKTOP_FILE_PID" "2397"
"GIT_ASKPASS" "rpostback-askpass"
"GNOME_DESKTOP_SESSION_ID" "this-is-deprecated"
"GNOME_KEYRING_CONTROL" "/tmp/keyring-m9K6wh"
"GNOME_KEYRING_PID" "1515"
"GPG_AGENT_INFO" "/tmp/keyring-m9K6wh/gpg:0:1"
"GTK_MODULES" "canberra-gtk-module:canberra-gtk-module"
"HOME" "/home/user"
"LANG" "en_IN"
"LANGUAGE" "en_US:en"
"LC_COLLATE" "en_US.UTF-8"
"LC_CTYPE" "en_US.UTF-8"
"LC_MESSAGES" "en_US.UTF-8"
"LD_LIBRARY_PATH" "/usr/lib/R/lib:/lib:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/i386/server"
"LN_S" "ln -s"
"LOGNAME" "user"
"MAKE" "make"
"MANDATORY_PATH" "/usr/share/gconf/ubuntu-2d.mandatory.path"
"PAGER" "/usr/bin/pager"
"PATH" "/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
"PWD" "/home/user"
"R_BROWSER" "xdg-open"
"R_BZIPCMD" "/bin/bzip2"
"R_DOC_DIR" "/usr/share/R/doc"
"R_GZIPCMD" "/bin/gzip"
"R_HOME" "/usr/lib/R"
"R_INCLUDE_DIR" "/usr/share/R/include"
"R_LIBS" "/usr/lib/rstudio/R/library"
"R_LIBS_SITE" "/usr/local/lib/R/site-library:/usr/lib/R/site-library:/usr/lib/R/library"
"R_LIBS_USER" "~/R/i686-pc-linux-gnu-library/3.1"
"R_PAPERSIZE" "letter"
"R_PAPERSIZE_USER" "a4"
"R_PDFVIEWER" "/usr/bin/xdg-open"
"R_PLATFORM" "i686-pc-linux-gnu"
"R_PRINTCMD" "/usr/bin/lpr"
"R_RD4PDF" "times,inconsolata,hyper"
"R_SESSION_TMPDIR" "/tmp/Rtmp7wgloJ"
"R_SHARE_DIR" "/usr/share/R/share"
"RS_PPM_FD_READ" "18"
"RS_PPM_FD_WRITE" "19"
"RS_RPOSTBACK_PATH" "/usr/lib/rstudio/bin/rpostback"
"RS_SHARED_SECRET" "115600967413966338811821464018"
"RSTUDIO" "1"
"RSTUDIO_SESSION_PORT" "20366"
"RSTUDIO_USER_IDENTITY" "user"
"R_SYSTEM_ABI" "linux,gcc,gxx,gfortran,?"
"R_TEXI2DVICMD" "/usr/bin/texi2dvi"
"R_UNZIPCMD" "/usr/bin/unzip"
"R_ZIPCMD" "/usr/bin/zip"
"SED" "/bin/sed"
"SESSION_MANAGER" "local/akd-HP-Mini-110-4100:@/tmp/.ICE-unix/1526,unix/akd-HP-Mini-110-4100:/tmp/.ICE-unix/1526"
"SHELL" "/bin/bash"
"SSH_AGENT_PID" "1563"
"SSH_AUTH_SOCK" "/tmp/keyring-m9K6wh/ssh"
"TAR" "/bin/tar"
"UBUNTU_MENUPROXY" "libappmenu.so"
"USER" "user"
"XAUTHORITY" "/home/user/.Xauthority"
"XDG_CONFIG_DIRS" "/etc/xdg/xdg-ubuntu-2d:/etc/xdg"
"XDG_CURRENT_DESKTOP" "Unity"
"XDG_DATA_DIRS" "/usr/share/ubuntu-2d:/usr/share/gnome:/usr/local/share/:/usr/share/"
"XDG_SEAT_PATH" "/org/freedesktop/DisplayManager/Seat0"
"XDG_SESSION_COOKIE" "c143c6cb80cfe9614354b2ab0000000d-1453572539.964572-1541574946"
"XDG_SESSION_PATH" "/org/freedesktop/DisplayManager/Session0"