Latex 乳胶(描述(…)是否与MiKTeX一起在knitr下工作?

Latex 乳胶(描述(…)是否与MiKTeX一起在knitr下工作?,latex,knitr,miktex,hmisc,Latex,Knitr,Miktex,Hmisc,创建文件时,请按如下方式描述.Rnw: \documentclass{article} \begin{document} <<results='asis'>>= require(Hmisc) latex(describe(cars), file="") @ \end{document} 我收到的错误消息表明,由latex(descripe())组合创建的latex有语法错误: LaTeX errors: P:/r/ellisp/test/describe.tex

创建文件时,请按如下方式描述.Rnw:

\documentclass{article}

\begin{document}

<<results='asis'>>=
require(Hmisc)
latex(describe(cars), file="")
@


\end{document}
我收到的错误消息表明,由latex(descripe())组合创建的latex有语法错误:

LaTeX errors:
P:/r/ellisp/test/describe.tex:65: LaTeX Error: Environment spacing undefined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help
Your command was ignored.
P:/r/ellisp/test/describe.tex:131: LaTeX Error: \begin{document} ended by \end{
spacing}.

See the LaTeX manual or LaTeX Companion for explanation.
以下是我的会话信息:

sessionInfo() R版本3.0.1(2013-05-16) 平台:x86_64-w64-mingw32/x64(64位)

编辑-这是由knitr创建的descripe.tex文档

\documentclass{article}\usepackage{graphicx, color}
%% maxwidth is the original width if it is less than linewidth
%% otherwise use linewidth (to make sure the graphics do not exceed the margin)
\makeatletter
\def\maxwidth{ %
  \ifdim\Gin@nat@width>\linewidth
    \linewidth
  \else
    \Gin@nat@width
  \fi
}
\makeatother

\definecolor{fgcolor}{rgb}{0.2, 0.2, 0.2}
\newcommand{\hlnumber}[1]{\textcolor[rgb]{0,0,0}{#1}}%
\newcommand{\hlfunctioncall}[1]{\textcolor[rgb]{0.501960784313725,0,0.329411764705882}{\textbf{#1}}}%
\newcommand{\hlstring}[1]{\textcolor[rgb]{0.6,0.6,1}{#1}}%
\newcommand{\hlkeyword}[1]{\textcolor[rgb]{0,0,0}{\textbf{#1}}}%
\newcommand{\hlargument}[1]{\textcolor[rgb]{0.690196078431373,0.250980392156863,0.0196078431372549}{#1}}%
\newcommand{\hlcomment}[1]{\textcolor[rgb]{0.180392156862745,0.6,0.341176470588235}{#1}}%
\newcommand{\hlroxygencomment}[1]{\textcolor[rgb]{0.43921568627451,0.47843137254902,0.701960784313725}{#1}}%
\newcommand{\hlformalargs}[1]{\textcolor[rgb]{0.690196078431373,0.250980392156863,0.0196078431372549}{#1}}%
\newcommand{\hleqformalargs}[1]{\textcolor[rgb]{0.690196078431373,0.250980392156863,0.0196078431372549}{#1}}%
\newcommand{\hlassignement}[1]{\textcolor[rgb]{0,0,0}{\textbf{#1}}}%
\newcommand{\hlpackage}[1]{\textcolor[rgb]{0.588235294117647,0.709803921568627,0.145098039215686}{#1}}%
\newcommand{\hlslot}[1]{\textit{#1}}%
\newcommand{\hlsymbol}[1]{\textcolor[rgb]{0,0,0}{#1}}%
\newcommand{\hlprompt}[1]{\textcolor[rgb]{0.2,0.2,0.2}{#1}}%

\usepackage{framed}
\makeatletter
\newenvironment{kframe}{%
 \def\at@end@of@kframe{}%
 \ifinner\ifhmode%
  \def\at@end@of@kframe{\end{minipage}}%
  \begin{minipage}{\columnwidth}%
 \fi\fi%
 \def\FrameCommand##1{\hskip\@totalleftmargin \hskip-\fboxsep
 \colorbox{shadecolor}{##1}\hskip-\fboxsep
     % There is no \\@totalrightmargin, so:
     \hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
 \MakeFramed {\advance\hsize-\width
   \@totalleftmargin\z@ \linewidth\hsize
   \@setminipage}}%
 {\par\unskip\endMakeFramed%
 \at@end@of@kframe}
\makeatother

\definecolor{shadecolor}{rgb}{.97, .97, .97}
\definecolor{messagecolor}{rgb}{0, 0, 0}
\definecolor{warningcolor}{rgb}{1, 0, 1}
\definecolor{errorcolor}{rgb}{1, 0, 0}
\newenvironment{knitrout}{}{} % an empty environment to be redefined in TeX

\usepackage{alltt}
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}

\begin{document}

\begin{kframe}
\begin{alltt}
\hlfunctioncall{require}(Hmisc)
\hlfunctioncall{latex}(\hlfunctioncall{describe}(cars), file = \hlstring{""})
\end{alltt}
\end{kframe}\begin{spacing}{0.7}
\begin{center}\textbf{ cars \\ 2 Variables~~~~~ 50 ~Observations}\end{center}
\smallskip\hrule\smallskip{\small
\vbox{\noindent\textbf{speed}

{\smaller
\begin{tabular}{ rrrrrrrrrrr }
n&missing&unique&Mean&.05&.10&.25&.50&.75&.90&.95 \\
50&0&19&15.4& 7.0& 8.9&12.0&15.0&19.0&23.1&24.0 \end{tabular}

\begin{verbatim}
          4 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25
Frequency 2 2 1 1  3  2  4  4  4  3  2  3  4  3  5  1  1  4  1
%         4 4 2 2  6  4  8  8  8  6  4  6  8  6 10  2  2  8  2
\end{verbatim}
}
\smallskip\hrule\smallskip
}
\vbox{\noindent\textbf{dist}\setlength{\unitlength}{0.001in}\hfill\begin{picture}(1.5,.1)(1500,0)\linethickness{0.6pt}
\put(0,0){\line(0,1){25}}
\put(15,0){\line(0,1){25}}
\put(90,0){\line(0,1){50}}
\put(150,0){\line(0,1){25}}
\put(165,0){\line(0,1){25}}
\put(180,0){\line(0,1){25}}
\put(195,0){\line(0,1){25}}
\put(225,0){\line(0,1){50}}
\put(240,0){\line(0,1){25}}
\put(270,0){\line(0,1){25}}
\put(300,0){\line(0,1){100}}
\put(330,0){\line(0,1){50}}
\put(375,0){\line(0,1){75}}
\put(405,0){\line(0,1){75}}
\put(420,0){\line(0,1){50}}
\put(480,0){\line(0,1){50}}
\put(495,0){\line(0,1){25}}
\put(555,0){\line(0,1){50}}
\put(570,0){\line(0,1){25}}
\put(600,0){\line(0,1){25}}
\put(630,0){\line(0,1){25}}
\put(660,0){\line(0,1){50}}
\put(675,0){\line(0,1){50}}
\put(735,0){\line(0,1){25}}
\put(780,0){\line(0,1){25}}
\put(810,0){\line(0,1){25}}
\put(825,0){\line(0,1){25}}
\put(855,0){\line(0,1){25}}
\put(930,0){\line(0,1){25}}
\put(990,0){\line(0,1){25}}
\put(1035,0){\line(0,1){25}}
\put(1050,0){\line(0,1){25}}
\put(1140,0){\line(0,1){25}}
\put(1155,0){\line(0,1){25}}
\put(1485,0){\line(0,1){25}}
\end{picture}

{\smaller
\begin{tabular}{ rrrrrrrrrrr }
n&missing&unique&Mean&.05&.10&.25&.50&.75&.90&.95 \\
50&0&35&42.98&10.00&15.80&26.00&36.00&56.00&80.40&88.85 \end{tabular}
\begin{verbatim}
lowest :   2   4  10  14  16, highest:  84  85  92  93 120 
\end{verbatim}
}
\smallskip\hrule\smallskip
}
}\end{spacing}





\end{document}

由于未定义
间距
环境,请添加

\usepackage{setspace}

在序言中,由于定义了
间距

,您的LaTeX文件需要一个
\end{document}
,但从错误中可以明显看出这一点。感谢@Werner,但原始的descripe.Rnw中有一个\end{document},它保存到descripe.tex。我已经编辑了这个问题,以包含knitr创建的完整descripe.tex文件。在我看来,这个问题可能与由于某种原因无法识别的\begin{…}命令有关,因此\begin{}和end{}命令不同步。如果
间距
未定义,您应该将包添加到序言中。好的,谢谢。我将不得不在另一台机器上尝试,因为我们的测试环境没有安装它,而且用户没有添加软件包的权限(尽管它在我们要求在下一阶段测试中包含的更长的软件包列表中)。有没有什么地方我可以查到那个错误消息来给我一个缺少哪个软件包的线索?是的,这在我有权安装软件包的其他环境中修复了它。如果你想让你的第二条评论成为一个答案,我会投票表决并打勾(如果你能提到你是如何知道这也是一个问题的,这样我就知道下次类似的事情发生时如何找出答案,那就太好了)。
locale:
[1] LC_COLLATE=English_New Zealand.1252  LC_CTYPE=English_New Zealand.1252   
[3] LC_MONETARY=English_New Zealand.1252 LC_NUMERIC=C                        
[5] LC_TIME=English_New Zealand.1252    

attached base packages:
[1] splines   graphics  datasets  grid      stats     grDevices utils    
[8] methods   base     

other attached packages:
 [1] x12_1.1-0        tseries_0.10-32  stringr_0.6.2    lubridate_1.3.0 
 [5] tables_0.7       Hmisc_3.12-2     Formula_1.1-1    survival_2.37-4 
 [9] stargazer_4.0    knitr_1.2        proto_0.3-10     extrafont_0.14  
[13] Defaults_1.1-1   scales_0.2.3     reshape2_1.2.2   plyr_1.8        
[17] ggplot2_0.9.3.1  foreign_0.8-53   mvtnorm_0.9-9995

loaded via a namespace (and not attached):
 [1] cluster_1.14.4     codetools_0.2-8    colorspace_1.2-2   dichromat_2.0-0   
 [5] digest_0.6.3       evaluate_0.4.4     formatR_0.9        gtable_0.1.2      
 [9] labeling_0.2       lattice_0.20-15    MASS_7.3-27        munsell_0.4.2     
[13] quadprog_1.5-5     RColorBrewer_1.0-5 rpart_4.1-1        Rttf2pt1_1.2      
[17] tools_3.0.1        zoo_1.7-10        
\documentclass{article}\usepackage{graphicx, color}
%% maxwidth is the original width if it is less than linewidth
%% otherwise use linewidth (to make sure the graphics do not exceed the margin)
\makeatletter
\def\maxwidth{ %
  \ifdim\Gin@nat@width>\linewidth
    \linewidth
  \else
    \Gin@nat@width
  \fi
}
\makeatother

\definecolor{fgcolor}{rgb}{0.2, 0.2, 0.2}
\newcommand{\hlnumber}[1]{\textcolor[rgb]{0,0,0}{#1}}%
\newcommand{\hlfunctioncall}[1]{\textcolor[rgb]{0.501960784313725,0,0.329411764705882}{\textbf{#1}}}%
\newcommand{\hlstring}[1]{\textcolor[rgb]{0.6,0.6,1}{#1}}%
\newcommand{\hlkeyword}[1]{\textcolor[rgb]{0,0,0}{\textbf{#1}}}%
\newcommand{\hlargument}[1]{\textcolor[rgb]{0.690196078431373,0.250980392156863,0.0196078431372549}{#1}}%
\newcommand{\hlcomment}[1]{\textcolor[rgb]{0.180392156862745,0.6,0.341176470588235}{#1}}%
\newcommand{\hlroxygencomment}[1]{\textcolor[rgb]{0.43921568627451,0.47843137254902,0.701960784313725}{#1}}%
\newcommand{\hlformalargs}[1]{\textcolor[rgb]{0.690196078431373,0.250980392156863,0.0196078431372549}{#1}}%
\newcommand{\hleqformalargs}[1]{\textcolor[rgb]{0.690196078431373,0.250980392156863,0.0196078431372549}{#1}}%
\newcommand{\hlassignement}[1]{\textcolor[rgb]{0,0,0}{\textbf{#1}}}%
\newcommand{\hlpackage}[1]{\textcolor[rgb]{0.588235294117647,0.709803921568627,0.145098039215686}{#1}}%
\newcommand{\hlslot}[1]{\textit{#1}}%
\newcommand{\hlsymbol}[1]{\textcolor[rgb]{0,0,0}{#1}}%
\newcommand{\hlprompt}[1]{\textcolor[rgb]{0.2,0.2,0.2}{#1}}%

\usepackage{framed}
\makeatletter
\newenvironment{kframe}{%
 \def\at@end@of@kframe{}%
 \ifinner\ifhmode%
  \def\at@end@of@kframe{\end{minipage}}%
  \begin{minipage}{\columnwidth}%
 \fi\fi%
 \def\FrameCommand##1{\hskip\@totalleftmargin \hskip-\fboxsep
 \colorbox{shadecolor}{##1}\hskip-\fboxsep
     % There is no \\@totalrightmargin, so:
     \hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
 \MakeFramed {\advance\hsize-\width
   \@totalleftmargin\z@ \linewidth\hsize
   \@setminipage}}%
 {\par\unskip\endMakeFramed%
 \at@end@of@kframe}
\makeatother

\definecolor{shadecolor}{rgb}{.97, .97, .97}
\definecolor{messagecolor}{rgb}{0, 0, 0}
\definecolor{warningcolor}{rgb}{1, 0, 1}
\definecolor{errorcolor}{rgb}{1, 0, 0}
\newenvironment{knitrout}{}{} % an empty environment to be redefined in TeX

\usepackage{alltt}
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}

\begin{document}

\begin{kframe}
\begin{alltt}
\hlfunctioncall{require}(Hmisc)
\hlfunctioncall{latex}(\hlfunctioncall{describe}(cars), file = \hlstring{""})
\end{alltt}
\end{kframe}\begin{spacing}{0.7}
\begin{center}\textbf{ cars \\ 2 Variables~~~~~ 50 ~Observations}\end{center}
\smallskip\hrule\smallskip{\small
\vbox{\noindent\textbf{speed}

{\smaller
\begin{tabular}{ rrrrrrrrrrr }
n&missing&unique&Mean&.05&.10&.25&.50&.75&.90&.95 \\
50&0&19&15.4& 7.0& 8.9&12.0&15.0&19.0&23.1&24.0 \end{tabular}

\begin{verbatim}
          4 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25
Frequency 2 2 1 1  3  2  4  4  4  3  2  3  4  3  5  1  1  4  1
%         4 4 2 2  6  4  8  8  8  6  4  6  8  6 10  2  2  8  2
\end{verbatim}
}
\smallskip\hrule\smallskip
}
\vbox{\noindent\textbf{dist}\setlength{\unitlength}{0.001in}\hfill\begin{picture}(1.5,.1)(1500,0)\linethickness{0.6pt}
\put(0,0){\line(0,1){25}}
\put(15,0){\line(0,1){25}}
\put(90,0){\line(0,1){50}}
\put(150,0){\line(0,1){25}}
\put(165,0){\line(0,1){25}}
\put(180,0){\line(0,1){25}}
\put(195,0){\line(0,1){25}}
\put(225,0){\line(0,1){50}}
\put(240,0){\line(0,1){25}}
\put(270,0){\line(0,1){25}}
\put(300,0){\line(0,1){100}}
\put(330,0){\line(0,1){50}}
\put(375,0){\line(0,1){75}}
\put(405,0){\line(0,1){75}}
\put(420,0){\line(0,1){50}}
\put(480,0){\line(0,1){50}}
\put(495,0){\line(0,1){25}}
\put(555,0){\line(0,1){50}}
\put(570,0){\line(0,1){25}}
\put(600,0){\line(0,1){25}}
\put(630,0){\line(0,1){25}}
\put(660,0){\line(0,1){50}}
\put(675,0){\line(0,1){50}}
\put(735,0){\line(0,1){25}}
\put(780,0){\line(0,1){25}}
\put(810,0){\line(0,1){25}}
\put(825,0){\line(0,1){25}}
\put(855,0){\line(0,1){25}}
\put(930,0){\line(0,1){25}}
\put(990,0){\line(0,1){25}}
\put(1035,0){\line(0,1){25}}
\put(1050,0){\line(0,1){25}}
\put(1140,0){\line(0,1){25}}
\put(1155,0){\line(0,1){25}}
\put(1485,0){\line(0,1){25}}
\end{picture}

{\smaller
\begin{tabular}{ rrrrrrrrrrr }
n&missing&unique&Mean&.05&.10&.25&.50&.75&.90&.95 \\
50&0&35&42.98&10.00&15.80&26.00&36.00&56.00&80.40&88.85 \end{tabular}
\begin{verbatim}
lowest :   2   4  10  14  16, highest:  84  85  92  93 120 
\end{verbatim}
}
\smallskip\hrule\smallskip
}
}\end{spacing}





\end{document}
\usepackage{setspace}