Hi:
I am trying to create a dynamic latex table using \Sexpr{} but it's not evaluating it. I also tried the example below without Sweave and also fails. I have also copied the Sweave.sty to my working directory but nothing seems to work. Do I need to have certain package in order to run \Sexpr{}?
\documentclass[a4paper]{article}
\usepackage{C:/R/R-2.8.1/share/texmf/Sweave}
\begin{document}
<<echo=false,results=hide>>=
library(lattice)
library(xtable)
data(cats, package="MASS")
@
\section*{The Cats Data}
Consider the \texttt{cats} regression example from Venables \& Ripley
(1997). The data frame contains measurements of heart and body weight
of \SExpr{nrow(cats)} cats (\Sexpr{sum(cats$Sex=="F")} female,
\Sexpr{sum(cats$Sex=="M")} male).
A linear regression model of heart weight by sex and gender can be
fitted in R using the command
<<>>=
lm1 = lm(Hwt~Bwt*Sex, data=cats)
lm1
@
Tests for significance of the coefficients are shown in
Table~\ref{tab:coef}, a scatter plot including the regression lines is
shown in Figure~\ref{fig:cats}.
\SweaveOpts{echo=false}
<<results=tex>>=
xtable(lm1, caption="Linear regression model for cats data.", label="tab:coef")
@
\begin{figure}
\centering
<<fig=TRUE,width=12,height=6>>=
print(xyplot(Hwt~Bwt|Sex, data=cats, type=c("p", "r")))
@
\caption{The cats data from package MASS.}
\label{fig:cats}
\end{figure}
\begin{center}
\end{center}
\end{document}
Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA
Sweave and \Sexpr{}
5 messages · Eric R., Felipe Carrillo, Dieter Menne
Felipe Carrillo <mazatlanmexico <at> yahoo.com> writes:
I am trying to create a dynamic latex table using \Sexpr{} but it's
not evaluating it. I also tried the
example below without Sweave and also fails. I have also copied the
Sweave.sty to my working directory but
nothing seems to work. Do I need to have certain package in order to
run \Sexpr{}?
\documentclass[a4paper]{article}
\usepackage{C:/R/R-2.8.1/share/texmf/Sweave}
\begin{document}
... rest removed
Your example works well in my setting when I replace the usepackage by
\usepackage{Sweave}
which is on my file name database path of latex. Make sure you run "update file
name database".
Maybe better start with a tiny example, such as
\documentclass[a4paper]{article}
\usepackage{Sweave}
\begin{document}
\Sexpr{"Hello"}
\end{document}
to locate the problem more precisely.
Dieter
Felipe: See Leisch's FAQ A18. http://www.statistik.lmu.de/~leisch/Sweave/FAQ.html#x1-20000A.18 You likely have R2HTML loaded (likely because you are using Tinn-R) and that causes some difficulties for Sweave that are easily solved as described in the FAQ.
Felipe Carrillo wrote:
Hi:
I am trying to create a dynamic latex table using \Sexpr{} but it's not
evaluating it. I also tried the example below without Sweave and also
fails. I have also copied the Sweave.sty to my working directory but
nothing seems to work. Do I need to have certain package in order to run
\Sexpr{}?
\documentclass[a4paper]{article}
\usepackage{C:/R/R-2.8.1/share/texmf/Sweave}
\begin{document}
<<echo=false,results=hide>>=
library(lattice)
library(xtable)
data(cats, package="MASS")
@
\section*{The Cats Data}
Consider the \texttt{cats} regression example from Venables \& Ripley
(1997). The data frame contains measurements of heart and body weight
of \SExpr{nrow(cats)} cats (\Sexpr{sum(cats$Sex=="F")} female,
\Sexpr{sum(cats$Sex=="M")} male).
A linear regression model of heart weight by sex and gender can be
fitted in R using the command
<<>>=
lm1 = lm(Hwt~Bwt*Sex, data=cats)
lm1
@
Tests for significance of the coefficients are shown in
Table~\ref{tab:coef}, a scatter plot including the regression lines is
shown in Figure~\ref{fig:cats}.
\SweaveOpts{echo=false}
<<results=tex>>=
xtable(lm1, caption="Linear regression model for cats data.",
label="tab:coef")
@
\begin{figure}
\centering
<<fig=TRUE,width=12,height=6>>=
print(xyplot(Hwt~Bwt|Sex, data=cats, type=c("p", "r")))
@
\caption{The cats data from package MASS.}
\label{fig:cats}
\end{figure}
\begin{center}
\end{center}
\end{document}
Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
View this message in context: http://www.nabble.com/Sweave-and-%5CSexpr%7B%7D-tp21841963p21847606.html Sent from the R help mailing list archive at Nabble.com.
Thaks Eric and Dieter:
It is working now although I still have to specify the path to Sweave.sty \usepackage{C:/R/R-2.8.1/share/texmf/Sweave}
and it doesn't evaluate \Sexpr{} when I simply use \usepackage{Sweave}. I placed Sweave.sty in the same folder where my rnw and tex file reside.
--- On Thu, 2/5/09, Eric R. <ericr at mcs.st-and.ac.uk> wrote:
From: Eric R. <ericr at mcs.st-and.ac.uk>
Subject: Re: [R] Sweave and \Sexpr{}
To: r-help at r-project.org
Date: Thursday, February 5, 2009, 1:03 AM
Felipe:
See Leisch's FAQ A18.
http://www.statistik.lmu.de/~leisch/Sweave/FAQ.html#x1-20000A.18
You likely have R2HTML loaded (likely because you are using
Tinn-R) and that
causes some difficulties for Sweave that are easily solved
as described in
the FAQ.
Felipe Carrillo wrote:
Hi: I am trying to create a dynamic latex table using
\Sexpr{} but it's not
evaluating it. I also tried the example below without
Sweave and also
fails. I have also copied the Sweave.sty to my working
directory but
nothing seems to work. Do I need to have certain
package in order to run
\Sexpr{}?
\documentclass[a4paper]{article}
\usepackage{C:/R/R-2.8.1/share/texmf/Sweave}
\begin{document}
<<echo=false,results=hide>>=
library(lattice)
library(xtable)
data(cats, package="MASS")
@
\section*{The Cats Data}
Consider the \texttt{cats} regression example from
Venables \& Ripley
(1997). The data frame contains measurements of heart
and body weight
of \SExpr{nrow(cats)} cats
(\Sexpr{sum(cats$Sex=="F")} female,
\Sexpr{sum(cats$Sex=="M")} male).
A linear regression model of heart weight by sex and
gender can be
fitted in R using the command <<>>= lm1 = lm(Hwt~Bwt*Sex, data=cats) lm1 @ Tests for significance of the coefficients are shown
in
Table~\ref{tab:coef}, a scatter plot including the
regression lines is
shown in Figure~\ref{fig:cats}.
\SweaveOpts{echo=false}
<<results=tex>>=
xtable(lm1, caption="Linear regression model for
cats data.",
label="tab:coef")
@
\begin{figure}
\centering
<<fig=TRUE,width=12,height=6>>=
print(xyplot(Hwt~Bwt|Sex, data=cats,
type=c("p", "r")))
@
\caption{The cats data from package MASS.}
\label{fig:cats}
\end{figure}
\begin{center}
\end{center}
\end{document}
Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained,
reproducible code.
-- View this message in context: http://www.nabble.com/Sweave-and-%5CSexpr%7B%7D-tp21841963p21847606.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Felipe Carrillo <mazatlanmexico <at> yahoo.com> writes:
It is working now although I still have to specify the path to Sweave.sty
\usepackage{C:/R/R-2.8.1/share/texmf/Sweave}
and it doesn't evaluate \Sexpr{} when I simply use \usepackage{Sweave}. I
placed Sweave.sty in the same
folder where my rnw and tex file reside.
If it works, keep it. If you, like me, do not like explicit paths, either copy Sweave.sty to the local tex directory and update your database; in Miktex, this is from the settings gui. Or add the Sweave path in share to you local tex directory (from the same dialog, next tab). Dieter