trouble running code in knitr

Here is my code to draw a plot.

library(dplyr)
library(ggplot2)
library(lubridate)
###Read in the raw data for June 2019 and June 2018
callsJune <- read.csv("Late Line June 2019.csv")
June2018 <-read.csv("Late Line June 2018.csv")

When I ran my code in RScript, it worked fine, but when I had it in RMarkdown and tried to knit it, I got this error message

  ordinary text without R code

  |..........................                                       |  40%
label: unnamed-chunk-1 (with options) 
List of 2
 $ echo   : logi FALSE
 $ message:

processing file: Late_Line_June_2019_compared_to_2018.Rmd
 logi FALSE


Attaching package: 'dplyr'

The following objects are masked from 'package:stats':

    filter, lag

The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union

Registered S3 methods overwritten by 'ggplot2':
  method         from 
  [.quosures     rlang
  c.quosures     rlang
  print.quosures rlang

Attaching package: 'lubridate'

The following object is masked from 'package:base':

    date

Quitting from lines 13-33 (Late_Line_June_2019_compared_to_2018.Rmd) 
Error in file(file, "rt") : cannot open the connection
Calls: <Anonymous> ... withVisible -> eval -> eval -> read.csv -> read.table -> file

Execution halted

I used setwd() and the working directory was fine running rScript. I don't know why knitr isn't working.

Working directory of your R Console and that of R Markdown are different. By default, it uses the parent directory of the .Rmd file. Take a look at this answer:

1 Like

The here package (along with RStudio Projects) can really help reduce R Markdown path headaches :grin:.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.