Unable to Knit R-Markdown due to unexplained error

I am trying to knit my r-markdown but every time I try and do it, I keep getting this same error, and no matter what I do nothing seems to fix it.

Error:
! object 'daily_activity' not found
Backtrace:
 1. utils::head(daily_activity)
Execution halted

What I am trying to do is, I have a csv file called "dailyActivity_merged" and I uploaded it to rstuido without a problem and everything is fine there, I then do is read the csv as this,

daily_activity <- read.csv("dailyActivity_merged.csv")

then I use the head() function to see the first few rows of the dataset and the dataset runs fine in the source code and i can see the data.frames but once I go to knit the project it give me the error above. Am I doing something wrong?

Did you read in the file inside the RMarkdown code?

So what I did was, I went to files in the bottom right of Rstudio and then clicked upload which then let me choose a file from my desktop, once I chose the correct csv file the file then showed up in the files tab. Then i did the read.csv command.

daily_activity <- read.csv("dailyActivity_merged.csv")

is there another way that I can grab a csv file from my desktop?

Everything in a markdown file is separate from everything else in your session. So you need to have the read command in the .rmd file.

Isn't the read command the one I did above? Or is there a different one I am supposed to do?

The CSV is location on my Mac desktop within a folder, but even when I tried

daily_activity <- read.csv("/Users/mac_name/Desktop/folder_name/second_folder_name/dailyActivity_merged.csv")

still nothing

Why don't you show us the .rmd file if it's not too long. (Copy and paste, rather than picture.)

sure this is what i got so far

Prepare Data Packages

library(tidyverse)
library(lubridate)
library(dplyr)
library(ggplot2)
library(tidyr)

Uploaded Data From FitBit Fitness Tracker Data

daily_activity <- read.csv("dailyActivity_merged.csv")
daily_intensities <- read.csv("dailyIntensities_merged.csv")
daily_steps <- read.csv("dailySteps_merged.csv")
daily_calories <- read.csv("dailyCalories_merged.csv")

That all looks correct. You might try the command

list.files()

to get a list of files and to be sure the file is there and spelled correctly.

Alright so I did the list.files() command and everything looks correct

list.files()
[1] "Bellabeat Overview.Rmd"      "Bellabeat-Overview.html"    
[3] "dailyActivity_merged.csv"    "dailyCalories_merged.csv"   
[5] "dailyIntensities_merged.csv" "dailySteps_merged.csv"      
[7] "project.Rproj" 

But every time I run the head() command it only shows the data.frames in the source code but when I knit everything together I keep getting the I mentioned above.

Still looks like you're doing everything right. Gotta admit that I'm out of ideas at the moment. Someone else maybe?

thank you for the help

Can you give us the complete Rmd code including YAMl that you have until after the

daily_activity <- read.csv("dailyActivity_merged.csv")
daily_intensities <- read.csv("dailyIntensities_merged.csv")
daily_steps <- read.csv("dailySteps_merged.csv")
daily_calories <- read.csv("dailyCalories_merged.csv")

part of your code.

As @ startz says every looks good but I think we need to see all the code to even guess at what is the problem.

This is everything that i have so far not a lot of code just a bunch of summaries.


title: "Bellabeat Case Study"
author: "Joseph LaBianca"
date: "2023-12-13"
output: html_document

knitr::opts_chunk$set(echo = TRUE)

Bellabeat Data Analysis Dataset

In this data analysis report, I delve into a dataset capturing non-Bellabeat smart devices between the 1st of April 2016 and the 31st of May 2016. It is sourced from the FitBit Fitness Tracker Data. Throughout this analysis, I aim to gain more insight into how consumers are using their smart devices.

About the Company

Bellabeat is a company that's pioneering into the fem-tech realm, Bellabeat is a women's wellness company that has helped millions of women track their cycle, pregnancies, and lives. Founded in 2014 their mission is to empower women to take control of their health by providing them with technology-driven solutions that blend design and function

Stakeholders

  • Urška Sršen: Bellabeat's cofounder and Chief Creative Officer
  • Sando Mur: Mathematician and Bellabeat's cofounder; key member of the Bellabeat executive team
  • Bellabeat marketing analytics team: A team of data analysts responsible for collecting, analyzing, and reporting data that helps guide Bellabeat's marketing strategy.

Report Stucture

This report is organized as the follows

  • Data Overview: dataset overview, dataset source.

  • Data Preprocessing: data cleaning, handling missing values, data visualizations, and key findings.

  • Data Analysis: statistical summaries, data visualizations.

  • Conclusions: summary of the main insights from the analysis.

  • Reference: references used in the report

Business Questions

This analysis aims to answer the following key business questions

  • 1. What are some trends in smart device usage?
  • 2. How could these trends in apply to Bellabeat customers?
  • 3. How could these trends help influence Bellabeat marketing strategy?

Prepare Data Packages

library(tidyverse)
library(lubridate)
library(dplyr)
library(ggplot2)
library(tidyr)
library(skimr)
library(tidyverse)

A small point: loading the tidyverse package will also load nine more packages, including lubridate, dplyr, ggplot2, and tidyr. All you need is

library(tidyverse)
library(skimr)

More importantly, where is the code to import the dailyActivity_merged.csv file? Even if you already ran read.csv("dailyActivity_merged.csv") you need to include that in the code that is run when knitting the R Markdown document. As @startz noted "Everything in a markdown file is separate from everything else in your session."

I think EconProf has it. A markdown document is the rough equivalent of starting a new RStudio session.

So what I did was I went to the bottom right where you can see what files and packages are being used and there is a button that says upload so I uploaded the files that way because every time I tried to call it from my desktop it says I can't do that. So what I thought to do next was to change the directory but it wouldn't let me do that either. So I thought that if I just uploaded it that way, it would work, but still nothing worked.

Uploading a file from your computer to the cloud is very different from importing it into the R environment. You have successfully uploaded the csv file but must then include

daily_activity <- read.csv("dailyActivity_merged.csv")

in a code chunk in your R Markdown document so it will import the file when knitting (which starts with an empty environment).

2 Likes

thank you so much that worked, I wasn't including it I don't know how I missed that thank you!

1 Like

This topic was automatically closed 45 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.