Nader Mehri
Nader Mehri

Reputation: 556

R-markdown cannot change working directory. Used to work properly

I have R-markdown codes that used to work properly on my laptop. I just ran my codes and got the following error. I tried to re-install the knitr and markdown package but the problem still resists. Here is the error:

cannot change working directory Calls: ... withCallingHandlers -> withVisible -> eval -> eval -> setwd Execution halted

And here are the few first lines of my codes:

---
output: 
  html_document:
  toc: true
  number_sections: true
geometry: margin= 0in
include:
 after_body: footer.html
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r, echo=FALSE, warning = FALSE, message=FALSE}
#Edit theses values to change it throughout the report
county<-"Butler"
pubDate<- "June 2018"
citeDate<-"2013"
```
```{r, echo=FALSE, warning = FALSE, message=FALSE}

Upvotes: 1

Views: 1291

Answers (2)

RDavey
RDavey

Reputation: 1909

Whenever I've had a problem like this it's been the knit directory setting that has tripped me up. Whilst it is not best practice to setwd() in a script, keeping a consistent practice of the knit directory settings (and noting this setting in the readme for others) will aid reproducibility.

For git version controlled code repositories, I favour the "Project Directory" knit setting, as this makes it consistent for Rmarkdown and R scripts and better allows for a subfolder layout such as that used for R package development (see here)

enter image description here

Upvotes: 0

Nader Mehri
Nader Mehri

Reputation: 556

I am not sure what is going on, but when I re-run the code I do not receive that error anymore. Instead, I get this error: Error: Must supply a symbol or a string as argument. I think something should be wrong on the following portion of my codes:

  education.year <- acs %>% 
  filter(Sex == "Total", `Age Group`=="All", `County Name` == county) %>% 
  select(`6th Grade or Less`, `7th- 12th (No Diploma)`, `High School Graduate`, 
         `Some College`, `Bachelor's Degree`, `Graduate Degree`)  %>% 
  gather(c(`6th Grade or Less`, `7th- 12th (No Diploma)`, `High School Graduate`, 
           `Some College`, `Bachelor's Degree`, `Graduate Degree`), EduPerc) 

P.S: My Rmarkdown code used to be work properly.

Upvotes: 1

Related Questions