Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I downloaded the most recent version of Miktex Basic Installer (2.9.5105). After following the Miktex's instructions, I began working through Nicola Satori's Sweave Tutorial.

The R portion of example 1 worked fine, however, when I compiled the .tex file, I received the error below.

!Latex Error: 'Sweave.sty' not found

After spending hours pouring over numerous forums, I found the reason why I received this error and the likely reason that you're receiving this error as well.

My answer below is the initial answer that I was looking for. Feel free to add comments and explanations, however, keep in mind that the instructions are simply to fix this error and allow Miktex to function properly when calling the Sweave package.

share|improve this question

migrated from stackoverflow.com Jan 9 at 15:25

This question came from our site for professional and enthusiast programmers.

    
If you're just getting started with sweave you might want to consider knitr instead. It's a slightly more modern tool for embedding R in TeX source. –  Ethan Bolker Jan 9 at 15:48

1 Answer 1

up vote 8 down vote accepted

The likely reason that this error is triggered is due to the texmf folder not being properly mapped to Miktex's root directory. Since Sweave.sty is positioned in a sub directory of texmf, Miktex never finds it.

Sweave.sty comes standard with current R downloads.

To properly map the texmf directory to Miktex's root directory, follow these instructions carefully.

  1. Locate the texmf directory inside the share folder in R. For me, the path was C:\Program Files\R\R-3.0.2\share\texmf but this can change from user to user
  2. Launch Miktex's Options via the start menu or by locating this exectuable C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\mo_admin.exe. You can also follow these instructions
  3. Click on the "Roots" tab and click "Add"
  4. Map the folder path to texmf that you located earlier.
  5. If you receive an error about the file being in use, make sure to close out of any open session of TeXworks.
  6. Click "Ok" and you're set to go.

Like I said above, this is the straight forward answer to get you out of the forums and exploring Miktek and Sweave.

Enjoy!

share|improve this answer
    
See also Create a local texmf tree in MiKTeX. –  Speravir Jan 10 at 1:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.