1

Below is the error I am getting:

Quitting from lines 46-48 (lesson3_student.rmd) 
Error in contrib.url(repos, "source") : 
  trying to use CRAN without setting a mirror
Calls: <Anonymous> ... withVisible -> eval -> eval -> install.packages -> contrib.url
In addition: Warning message:
In in_dir(opts_knit$get("root.dir") %n% input_dir(), evaluate::evaluate(code,  :
  You changed the working directory to /Users/Madiyar/Desktop/Facebook Data (probably via setwd()). It will be restored to /Users/Madiyar/Downloads. See the Note section in ?knitr::knit
Execution halted

Thanks for help

Mi-Creativity
  • 9,554
  • 10
  • 38
  • 47
Madik088
  • 77
  • 1
  • 5
  • 2
    Please don't put `install.packages(…)` code in Rmd documents. Most folks want to manage their own package library. – hrbrmstr Feb 20 '16 at 17:11

1 Answers1

2

The error seems fairly clear to me; you're "trying to use CRAN without setting a mirror"; the problem is that knitting runs in non-interactive mode. Try putting

options(repos="https://cran.rstudio.com" )

in your code. I would say by the way that in knitted code you should probably not

  • run install.packages() (as @hrbrmstr says in the commenbts, "[m]ost folks want to manage their own package library")
  • call setwd() to set your working directory manually
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • comments are technically not for "thank yous" -- if you want to convey your appreciation, accept the answer (click on the checkmark) and/or upvote – Ben Bolker Feb 20 '16 at 18:46
  • 1
    The problem is not that `knitr` uses "non-interactive mode", it's because RStudio is not involved. See [scoa's answer here](http://stackoverflow.com/questions/33969024/install-packages-fails-in-knitr-document-trying-to-use-cran-without-setting-a). – CL. Feb 21 '16 at 15:28