Appologies from the go, still getting my head around all the functions in R and RStudio, so some of you might think I'm a total idiot for asking this. BTW: I've translated some of the stuff produced by R from German to english.
I'm running RStudio Version 0.97.551 on a MAC OS X, Version 10.8.5.
I'm trying to compile a PDF using knitr. I installed knitr, ran it by using library() and set my working directory to the same directory as my default working directory, which is also the same folder that contains the .txt files I use as my datasets. And have chosen knitr as the default for weaving Rnw files. I then installed MacTex basic from http://tug.org/mactex/morepackages.html to use for my LaTex which is a subset from TeXLive (2013).
So far so good.
I then open a new Sweave file, RStudio has recognized that I'm using some form of TeX program and then plug in the following:
\documentclass{article}
\begin{document}
\title{My first Knitr Output File}
\author{Oliver M. Fisher, MD}
\maketitle{BMI Category Crosstabulation}
<<>>=
attach(MIC1ELISANEW)
tab1=table(BMICat, Diagnosis)
tab1
summary(tab1)
@
<<>>=
tab1=table(MIC1ELISANEW$BMICat, MIC1ELISANEW$Diagnosis)
summary(tab1)
@
\end{document}
Hit "compile PDF" which gives me this log
grDevices::pdf.options(useDingbats = FALSE); require(knitr); opts_knit$set(concordance =TRUE); knit('Example.Rnw')
Opening packet: knitr
Warning:
Packet ‘knitr’ was developed under R Version 3.0.2
processing file: Example.Rnw
|............. | 20%
ordinary text without R code
|.......................... | 40%
label: unnamed-chunk-1
|....................................... | 60%
ordinary text without R code
|.................................................... | 80%
label: unnamed-chunk-2
|.................................................................| 100%
ordinary text without R code
output file: Example.tex
[1] "Example.tex"
>
>
Running pdflatex on Example.tex...completed
Created PDF: ~/Documents/Australia/AMR : Gastro/Papers/Oliver/MIC1/Datasets/ELISA/Example.pdf
And opens a PDF, that looks the following ("nicht gefunden" means "not found" in English):
My first Knitr Output File
Oliver M. Fisher, MD February 3, 2014
BMI Category Crosstabulation
attach(MIC1ELISANEW)
Error: Objekt ’MIC1ELISANEW’ nicht gefunden
tab1 = table(BMICat, Diagnosis)
Error: Objekt ’BMICat’ nicht gefunden
tab1
Error: Objekt ’tab1’ nicht gefunden
summary(tab1)
Error: Objekt ’tab1’ nicht gefunden
tab1 = table(MIC1ELISANEW$BMICat, MIC1ELISANEW$Diagnosis)
Error: Objekt ’MIC1ELISANEW’ nicht gefunden
summary(tab1)
Error: Objekt ’tab1’ nicht gefunden
I've tried inputing the R code by either a) copy&pasting it from an R script file, copy&pasting it from the RStudio console and also sending it to the "source" by clicking on that icon in the RStudio history window. Nothing works. If anyone could tell me what I'm doing wrong, I'd be very grateful.
Thanks,
Oliver
--
You received this message because you are subscribed to the Google Groups "knitr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to knitr+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
\begin{document} \title{My first Knitr Output File} \author{Oliver M. Fisher, MD} \maketitle{BMI Category Crosstabulation}
<<>>=
read.delim("~/relativepathtofile")
MIC1ELISANEW<-read.table("~/relativepathtofile", header=T)
@
<<>>=
attach(MIC1ELISANEW)
tab1=table(BMICat, Diagnosis)
tab1
summary(tab1)
@
<<>>=
tab1=table(MIC1ELISANEW$BMICat, MIC1ELISANEW$Diagnosis)
summary(tab1)
@
\end{document}I wrote the Stack overflow answer.
Please note,
read.delim("~/relativepathtofile")
does not assign the results to anything (therefore is useless).
My suggestion of `read.table`, was to prompt you to read in the data (the same way you would read it into an new R session)
In
MIC1ELISANEW<-read.table("~/relativepathtofile", header=T)
replace read.table with the appropriate "read" function (delim / csv whatever you used originally), and replace 'relativepathtofile' with
the path to the file which contains the data (relative to the directory in which the .rnw script is stored).
Michael
From: kn...@googlegroups.com [kn...@googlegroups.com] on behalf of OFish [ofis...@gmail.com]
Sent: Thursday, 6 February 2014 11:09 AM
Subject: [knitr] Re: Knitr PDF ok, but no content and error messages
\end{document}
Cheers,
O.
Thanks.
\end{document}
output file: Example.tex
Created PDF: ~/Documents/Australia/AMR : Gastro/Papers/Oliver/MIC1/Datasets/ELISA/Example.pdf