I am trying to convert an assignment for school into a pdf file. I'm using the knit function and I get the following error message every time. Can someone please explain why and how to fix it? Thanks.
processing file: Week-1---Lab.spin.Rmd
Error in contrib.url():
! trying to use CRAN without setting a mirror
Backtrace:
▆
└─utils::install.packages("psych")
└─utils::contrib.url(repos, "source")
Quitting from Week-1---Lab.spin.Rmd:2-19 [unnamed-chunk-1]
Execution halted
#Set Working Directory #Data Entry
setwd("C:/Users/polly/Downloads")
TVdat <- read.csv("TvHours2018.csv")
This is what is in the markdown document. I have the install.packages() there because that was part of the instructions for the assignment. Maybe there is a different way? This is my first semester ever using R.
#Describe data
install.packages("psych")
library(psych)
describe(TVdat)
Yup, remove install.packages("psych") from your R Markdown file and keep library(psych). This will fix your issue!
You only need to install a package once on your computer. When you install packages, you should do so directly in the R console, not inside an R Markdown file. You only ever have to do this once for each package (until you upgrade R to a major version, like 4.2 -> 4.3, because that creates a new folder for all your packages). Once the package is installed, you can use the library() command inside any R Markdown file (or any other R script) to tell that specific session to load the package from your computer.
You're getting that error because you're trying to install a package from within the R Markdown document every time you knit it. Every time you knit an R Markdown session, R creates a new session just for that process. Because it's a fresh session, it doesn't know where to go to download new packages. The "mirror" is just the website or server it needs to download packages from, and since you haven't told it which one to use, it gets confused.