Why does RMarkdown not work for anything?

I can share my code if needed but honestly everything worked in my R analysis, but when I run the same code when creating a markdown, nothing works. I had an issue with Read.csv in RMarkdown and was able to find a solution to that but now it's saying the dataset I loaded the data into doesn't exist. I did a notebook on Kaggle and it worked perfectly. Why is it so difficult to use RMarkdown? It should go hand in hand with with R, it's ridiculous. Here's the code I have in order:

knitr::opts_chunk$set(echo = TRUE)
# local folder for this knit action
getwd()
library(tidyverse)
library(readr)
library(janitor)
library(dplyr)
library(lubridate)
Trips_2021_09 <- read.csv("202109-divvy-tripdata.csv")
Trips_2021_10 <- read.csv("202110-divvy-tripdata.csv")
Trips_2021_11 <- read.csv("202111-divvy-tripdata.csv")
Trips_2021_12 <- read.csv("202112-divvy-tripdata.csv")
Trips_2022_01 <- read.csv("202201-divvy-tripdata.csv")
Trips_2022_02 <- read.csv("202202-divvy-tripdata.csv")
Trips_2022_03 <- read.csv("202203-divvy-tripdata.csv")
Trips_2022_04 <- read.csv("202204-divvy-tripdata.csv")
Trips_2022_05 <- read.csv("202205-divvy-tripdata.csv")
Trips_2022_06 <- read.csv("202206-divvy-tripdata.csv")
Trips_2022_07 <- read.csv("202207-divvy-tripdata.csv")
Trips_2022_08 <- read.csv("202208-divvy-tripdata.csv")
str(Trips_2021_09) # And here's where my error message pops up

The error message says: Error in str(Trips_2021_09) : object 'Trips_2021_09' not found
Calls: ... withVisible -> eval_with_user_handlers ->
eval _> eval Execution halted

I'm completely a case study and R markdown is all I have left but has taken the longest time to complete.

I think Rmarkdown runs in its own environment. Try using the full path to your files.

RMarkdown defaults to the home directory in the same way that R scripts do.

For set the work directory, use this:

You need select the folder that contain the files .csv, like said the other R user.

2 Likes

Hey there @M_AcostaCH,

I have tried so many things and I actually had to copy my files and upload them into the file it was saying they were in and when I set the directory to that file, it worked! Thank you so much.

1 Like

To avoid this in the future, try to use an R project environment. This will set the default path to the project folder and you won't be bothered with pathways anymore.

2 Likes

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.