\documentclass{article}
\title {Using \LaTeX with R}
\author {Matthew Richardson\\
Written for Experts Exchange
}
\begin{document}
\SweaveOpts{concordance=TRUE}
\maketitle
\section*{Incorporating R code}
\end{document}
<<>>=
(code)
@
You want to include this in the body of your script (see below)
label=fig1,fig=TRUE,echo=FALSE
<<echo=FALSE, results=hide>>=
library(XML)
library(httr)
url <- GET("http://en.wikipedia.org/wiki/A_Song_of_Ice_and_Fire")
table <- readHTMLTable(rawToChar(url$content), stringsAsFactors = F)
str(table)
table[[2]]
books <- as.data.frame(table[[2]])[,-1]
names(books) <- c("Title","Pages","Chapters","Audio Length","U.S. Release")
books[,2] <- c(704,768,992,753,1056,NA,NA)
@
<<results=tex>>=
library(xtable)
xtable(books)
@
<<label=fig1,fig=TRUE,echo=FALSE>>=
plot(1:7,books[,2],xlim=c(1,5),xlab="Book Number",ylab="Number of Pages",main="Number of Pages per Book")
@
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)