Graphics, Figures & TablesSweave does not work

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
fontana
Posts: 4
Joined: Sat May 22, 2010 11:50 pm

Sweave does not work

Post by fontana »

Hi everyone,

I am trying to tranfer my graphical outputs from R to Latex using Sweave (if there is a different easier option please let me know), and I am having some problems.

After writing my tex file in WinEdt, saving it as "test.Rnw", running the file in R using "Sweave("test.Rnw")", I try to run the produced test.tex file in WinEdt. and get the following error:

"! File ended while scanning use of \FV@BeginScanning.
<inserted text>

I have already ensured the the sweave.sty file is in the same directory as test.tex and I have also reinstalled R in a folder withouth blanks. Please find my code below:

\documentclass[a4paper]{article}

\usepackage{Sweave}
\begin{document}

\begin{Scode}
studentdata = read.table("C:/Temp/My Dropbox/Literature/Learn R and Bayes/LearnBayes/data/studentdata.txt", sep = "\t", header = TRUE)
data(studentdata)
studentdata[1,]
attach(studentdata)
t=table(Drink)
\end{Scode}


\begin{Scode}{fig=TRUE,echo=FALSE}
barplot(t,xlab="Drink",ylab="Count")
\end{Scode}

\end{document}

I am thankful for any ideas.

Fontana

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: Sweave does not work

Post by localghost »

Perhaps it is the path of the file that is read into the variable »studentdata«. It contains blank spaces. On the other hand the error message suggests that there is a brace missing. But your code appears correct.


Best regards and welcome to the board
Thorsten
fontana
Posts: 4
Joined: Sat May 22, 2010 11:50 pm

Re: Sweave does not work

Post by fontana »

Thank you, Thorsten.

I actually also have the exact same error message when I run the examples given on the page of Friedrich Fleisch's webpage. I save the files with an .Rnw ending and then run them in dynare using Sweave("name.Rnw") and then try to run the produced .tex file in Latex regularly. Is there maybe a step in between that I am missing.

Another fact: When I did this the first time, Latex wanted to install some package, as I left my computer during the installation process I do not know for sure if this was successful. Do I need an additional package to run Sweave, I am aware that the codes usually load the Sweave package in the beginning, but I could not locate a Sweave package in the MikTex package installation tool.

PS:I just noticed you are from Braunschweig, I was born in the area (Salzgitter).
Post Reply