0

I'm following the following guide: https://joshldavis.com/2014/04/12/beginners-tutorial-for-knitr/

I've installed the knitr package and run it in R, and I'm trying to copy and paste the example from the link above:

From ISLR: Chapter 3, Problem 14.

Using a created simulated data, answer the questions regarding simple
linear regression.

<<>>=
# Ensure consistent values
set.seed(1)

# Create uniform distribution for first input
x1 <- runif(100)

# Normal distribution for second input
x2 <- 0.5 * x1 + rnorm(100) / 10

# Our Linear Model
y <- 2 + (2 * x1) + (.3 * x2) + rnorm(100)
@

However, when I try to run it, I get the following error in Latex:

! You can't use `macro parameter character #' in horizontal mode.
l.30 #
       Ensure consistent values
? 

I'm not quite sure what I'm doing wrong here? Is there any package I'm supposed to run in Latex as well?

  • The file should be a normal and complete LaTeX file (i.e., starting with \documentclass ... and ending with \end{document}) but with the .Rnw extension, and configure Texmaker properly. Please add a minimal working example (MWE) of a .Rnw and the configuration of the command that you run. I you are new with nitr files, check first that your first .Rnw file can be compiled with RStudio before to deal with configuration of Texmaker. – Fran Aug 30 '18 at 20:06
  • Duplicate on SO – Troy Aug 30 '18 at 23:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.