0

Code

hello.Rnw:

\documentclass{article}

\begin{document}
\SweaveOpts{concordance=TRUE}

\end{document}

Commands:

rnwfile <- system.file("Sweave", "hello.Rnw", package = "utils")
Sweave(rnwfile)

Output:

Error in SweaveReadFile(file, syntax, encoding = encoding) : no Sweave file with name ‘’ found

Question

What is the problem here? Using another more complex file outputs the same. If I add to Sweave() only the path of the file it works for hello.Rnw but not for more complex files. Then the output is: "Error: ‘test.Rnw’ is not ASCII and does not declare an encoding".

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
b4154
  • 353
  • 3
  • 4
  • 14

1 Answers1

2

The system.file() function is for locating files that are installed as part of an R package. For example, if you want to run Sweave examples that come with R, they have to be the ones that are actually provided, e.g.

list.files(system.file("Sweave",package="utils"))
## [1] "example-1.Rnw"     "Sweave-test-1.Rnw"
Sweave(system.file("Sweave","example-1.Rnw",package="utils"))

works fine. (You may have been confused by the ?Sweave documentation, which uses this syntax - it's not a necessary part of the Sweave workflow, just used there to retrieve an example input file.)

If you want to run Sweave() on your own .Rnw files, you need to make sure that they are in your working directory (or specify the full path); see ?setwd/?getwd.

We would need to see test.Rnw in order to know what the problem is there.

If you're not attached to Sweave, I would strongly recommend looking into the knitr package: it does the same things as Sweave, but (IMO) better. (It's also very well documented.)

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • The purpose is to create the command which is done by the button COMPILE PDF. – b4154 Feb 11 '16 at 16:25
  • I will tell you if I have any other outputs. I will try – b4154 Feb 11 '16 at 16:27
  • You could have asked that question directly ... `knitr::knit2pdf("myfile")`, see http://stackoverflow.com/questions/34591487/difference-compile-pdf-button-in-rstudio-vs-knit-and-knit2pdf – Ben Bolker Feb 11 '16 at 17:46
  • Now Im using Sweave2knitr() to create knitr file and then knit2pdf(), but output is ==> Fatal error occurred, no output PDF file produced!. Using "COMPILE PDF" over Sweave Plugin when Rnw file is open everything works fine – b4154 Feb 15 '16 at 14:28
  • Now the processing works but the PDF-output looks terrible. – b4154 Feb 15 '16 at 14:39
  • 1
    it's going to be really, really hard to remotely troubleshoot your R/Sweave/LaTeX setup ... – Ben Bolker Feb 15 '16 at 14:46
  • with `knit2pdf` the output looks ugly. – b4154 Feb 16 '16 at 08:03
  • I sympathize, but there's really not enough information here to help you. If you still need help and can't get any local help (which would probably be the easiest thing at this point), you should ask another question that carefully details the steps you have taken so far. An image of your "ugly" `knit2pdf` output would be helpful. (Just to clarify, clicking on the "Compile PDF" button *does* give reasonable output?) – Ben Bolker Feb 16 '16 at 15:57
  • Clicking on the "Compile PDF" creates an structured and readable output. Tomorrow I will try to give you an example output, to understand the problem of the output. – b4154 Feb 17 '16 at 13:34
  • After trying I'm getting other outputs: New question: http://stackoverflow.com/questions/35603194/error-compiling-rnw-to-tex – b4154 Feb 24 '16 at 13:13