R markdown failure to knit

Hello,

I have been trying to knit my R markdown file for a while now, I use a Mac Pro M2 and I've been getting error messages.

This is the error message that keeps popping up;
processing file: Bikeshare.Rmd
|.............. | 28% [merge data frames]
Quitting from lines 53-54 [merge data frames] (Bikeshare.Rmd)

Error in bind_rows():
! could not find function "bind_rows"
Execution halted

There the codes are all correct because I get results. I can see all results on the R markdown visual page. Knitting only work if I select the "showing nothing (don't run code)" option in all the code chunks. I have restarted R multiple times, even went as far as uninstalling and reinstalling.

Any help would be much appreciated. Thank you.

Hi welcome to the forum.

I think we need to see your code and some sample data. See:
FAQ Asking Questions

A handy way to supply some sample data is the dput() function. In the case of a large dataset something like dput(head(mydata, 100)) should supply the data we need. Just do dput(mydata) where mydata is your data. Copy the output and paste it here between
```

```

Did you have a library statement in your .Rmd file like

library(dplyr)

?

I could not upload my data but I tried knitting with the 'penguins' data frame from the popular 'palmerpenguins' package and I got the same result.

summary(penguins)
ggplot(data = penguins) +
  geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g, color = species))

Here is the result I got again:

processing file: Penguins.Rmd

Quitting from lines 19-20 [cars] (Penguins.Rmd)
Error:
! object 'penguins' not found
Backtrace:

  1. base::summary(penguins)
    Execution halted

Please note that I have installed the required packages.

Yes, I do.

I also have the tidyverse, ggplot2, janitor, skimr, lubridate packages.

but apparently now you did not do in the .Rmd file

library(palmerpenguins)

I actually did. I was just trying to keep the reply brief. But I'll give you a full run down of the code chunks and the new error message now.

install.packages("palmerpenguins")
library(palmerpenguins)
View(penguins)
summary(cars)
ggplot(data = penguins) +
  geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g, color = species))

The error message:
processing file: Penguins.Rmd
|..................... | 40% [unnamed-chunk-1]
Quitting from lines 13-14 [unnamed-chunk-1] (Penguins.Rmd)

Error in contrib.url():
! trying to use CRAN without setting a mirror
Backtrace:

  1. utils::install.packages("palmerpenguins")
  2. utils::contrib.url(repos, "source")
    Execution halted

This . Rmd file works for me. And do not install a package inside an . Rmd file !

---
title: "Untitled"
output: html_document
date: "2023-10-13"
---

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

## R Markdown

This is an R Markdown document. ....

```{r myplot }
library(palmerpenguins)
summary(penguins)
library(ggplot2)
ggplot(data = penguins) +
geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g, color = species))
```

I did the exact thing and it still did not work. At this point I feel its an OS incompatibility problem.

Similar to @ HanOostdijk's code.

We really need to see the YAML and such things as library calls. Don't keep it too simple as that makes it harder to trouble shoot. I do not think you can really do a view() in an Rmd file.

---
title: "Birds"
author: "jrk"
date: "`r Sys.Date()`"
output: pdf_document
---

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

It was a dark and stormy night

summary(cars)

Not a creature was stirring, not even a mouse.

ggplot(penguins) +
         geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g, color = species))

So, knitting is successful with these codes using the 'penguin' data frame. But it does not work knit with frame. Keep in mind that the codes run successfully. I see the results but the problem is the knitting.

Here's the full code chunk;

---
title: "Cyclistic Bike-Share trip data"
author: "Chuku Joel"
date: "`r Sys.Date()`"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(dplyr)
library(skimr)
library(janitor)
library(lubridate)
library(ggplot2)
```

# Cyclistic Bike-Share trip data

![](upload://v3VJ6oUdwYtlP7mIgXMVQZM4gJv.png)

This document contains analysis of the Cyclistic Bike-share trip data for January, February and March 2022, with the aim of answering **How annual members and casual riders use Cyclistic bikes differently**.

#### First install and load packages needed for a successful analysis:

-   install.packages("tidyverse")
-   install.packages("dplyr")
-   install.packages("skimr")
-   install.packages("lubridate")
-   install.packages("janitor")
-   install.packages("ggplot2")

#### Import and merge data frames

Import the data frames for January, February and March, merge using 'bind_rows' function:

```{r merge data frames}
bikeshare_tripdata <- bind_rows(X202201_divvy_tripdata, X202202_divvy_tripdata, X202203_divvy_tripdata)
```

#### Get summary of the data set:

```{r echo=TRUE}
summary(bikeshare_tripdata)
```
```{r}
head(bikeshare_tripdata)
```

```{r}
colnames(bikeshare_tripdata)
```

```{r}
skim_without_charts(bikeshare_tripdata)
```

#### Finding the days of the week riders use Bike-Share:

```{r}
bikeshare_tripdata <- bikeshare_tripdata %>%
  mutate(day_of_week = weekdays(started_at))
```

```{r}
bikeshare_tripdata %>%
  distinct(day_of_week)
```

#### Finding the most popular day for riders

```{r}
ggplot(data = bikeshare_tripdata) +
  geom_bar(mapping = aes(x = day_of_week, fill = day_of_week)) +
  labs(x = "Day of week", y = "Count", title = "Most popular day for riders", caption = "Monday is the most popular day")
```

Thank you but this is pretty close to unusable. Can you give us the same code in raw format as @ HanOostdijk and I have done in the examples above.

As HanOostdijk points out you really should not install {packages} in an Rmd file. They should already be installed.

We need to see some actual data.

bikeshare_tripdata <- bind_rows(X202201_divvy_tripdata, X202202_divvy_tripdata, X202203_divvy_tripdata)

tells us nothing .

Can you supply some sample data, see my post above, or provide a link the data you are using.

Thanks

When you knit an Rmd document the code gets executed in a clean environment other than the one you are currently working on so the mentioned data frames do not exist there. You need to include the necessary code to import the data frame into memory, in your Rmd document itself, for example, if the data frame comes from a csv file you would include something like this: your_data_frame <- read.csv("path_to_file.csv").

I hope this does the trick. I'm sorry I am a bit slow. I am just a week old with R.

dput(bikeshare_data <- tibble::tribble(
                              ~ride_id,  ~rideable_type,           ~started_at, ~start_at_date, ~start_at_time,             ~ended_at, ~end_at_date, ~end_at_time,             ~start_station_name, ~start_station_id,               ~end_station_name, ~end_station_id,  ~start_lat,   ~start_lng,    ~end_lat,     ~end_lng, ~member_casual, ~ride_length, ~day_of_week,
                    "C2F7DD78E82EC875", "electric_bike", "2022-01-13 11:59:47",   "2022-01-13",     "11:59:47", "2022-01-13 12:02:44", "2022-01-13",   "12:02:44",      "Glenwood Ave & Touhy Ave",             "525",          "Clark St & Touhy Ave",        "RP-007",  42.0128005,   -87.665906, 42.01256012, -87.67436712,       "casual",    "0:02:57",           5L,
                    "A6CF8980A652D272", "electric_bike",  "2022-01-10 8:41:56",   "2022-01-10",      "8:41:56",  "2022-01-10 8:46:17", "2022-01-10",    "8:46:17",      "Glenwood Ave & Touhy Ave",             "525",          "Clark St & Touhy Ave",        "RP-007",   42.012763,  -87.6659675, 42.01256012, -87.67436712,       "casual",    "0:04:21",           2L,
                    "BD0F91DFF741C66D",  "classic_bike",  "2022-01-25 4:53:40",   "2022-01-25",      "4:53:40",  "2022-01-25 4:58:01", "2022-01-25",    "4:58:01", "Sheffield Ave & Fullerton Ave",    "TA1306000016", "Greenview Ave & Fullerton Ave",  "TA1307000001", 41.92560188, -87.65370804,    41.92533,     -87.6658,       "member",    "0:04:21",           3L,
                    "CBB80ED419105406",  "classic_bike",  "2022-01-04 0:18:04",   "2022-01-04",      "0:18:04",  "2022-01-04 0:33:00", "2022-01-04",    "0:33:00",      "Clark St & Bryn Mawr Ave",    "KA1504000151",     "Paulina St & Montrose Ave",  "TA1309000021",   41.983593,   -87.669154,   41.961507,   -87.671387,       "casual",    "0:14:56",           3L,
                    "DDC963BFDDA51EEA",  "classic_bike",  "2022-01-20 1:31:10",   "2022-01-20",      "1:31:10",  "2022-01-20 1:37:12", "2022-01-20",    "1:37:12",   "Michigan Ave & Jackson Blvd",    "TA1309000002",        "State St & Randolph St",  "TA1305000029",    41.87785,    -87.62408, 41.88462107, -87.62783423,       "member",    "0:06:02",           5L,
                    "A39C6F6CC0586C0B",  "classic_bike", "2022-01-11 18:48:09",   "2022-01-11",     "18:48:09", "2022-01-11 18:51:31", "2022-01-11",   "18:51:31",         "Wood St & Chicago Ave",             "637",       "Honore St & Division St",  "TA1305000034",   41.895634,   -87.672069,   41.903119,   -87.673935,       "member",    "0:03:22",           3L,
                    "BDC4AB637EDF981B",  "classic_bike", "2022-01-30 18:32:52",   "2022-01-30",     "18:32:52", "2022-01-30 18:49:26", "2022-01-30",   "18:49:26",   "Oakley Ave & Irving Park Rd",    "KA1504000158",        "Broadway & Sheridan Rd",         "13323", 41.95434085, -87.68607962,   41.952833,   -87.649993,       "member",    "0:16:34",           1L,
                    "81751A3186E59A6B",  "classic_bike", "2022-01-22 12:20:02",   "2022-01-22",     "12:20:02", "2022-01-22 12:32:06", "2022-01-22",   "12:32:06", "Sheffield Ave & Fullerton Ave",    "TA1306000016",      "Damen Ave & Clybourn Ave",         "13271", 41.92560188, -87.65370804,   41.931931,   -87.677856,       "member",    "0:12:04",           7L,
                    "154222B86A338ABD", "electric_bike",  "2022-01-17 7:34:41",   "2022-01-17",      "7:34:41",  "2022-01-17 8:00:08", "2022-01-17",    "8:00:08",          "Racine Ave & 15th St",           "13304",  "Clinton St & Washington Blvd",        "WL-012", 41.86125133, -87.65650017,    41.88338,    -87.64117,       "member",    "0:25:27",           2L)

These are the code chunks so far:

summary(bikeshare_data)
head(bikeshare_tripdata)
colnames(bikeshare_tripdata)
skim_without_charts(bikeshare_tripdata)
bikeshare_tripdata <- bikeshare_tripdata %>%
  mutate(day_of_week = weekdays(started_at))
bikeshare_tripdata %>%
  distinct(day_of_week)
ggplot(data = bikeshare_tripdata) +
  geom_bar(mapping = aes(x = day_of_week, fill = day_of_week)) +
  labs(x = "Day of week", y = "Count", title = "Most popular day for riders", caption = "Monday is the most popular day")
bikeshare_tripdata <- bikeshare_tripdata %>%
  mutate(ride_months = month(started_at))
ggplot(data = bikeshare_tripdata) +
  geom_bar(mapping = aes(x = member_casual, fill = member_casual)) +
  labs(x = "Rider types", y = "Ride count")
ggplot(data = bikeshare_tripdata) +
  geom_bar(mapping = aes(x = member_casual, fill = member_casual)) +
  facet_wrap(~ride_months, labeller = labeller(ride_months = c("1" = "January", "2" = "February", "3" = "March"))) +
  labs(title = "Riders growth rate", subtitle = "Showing the growth rate of riders from January to March", x = "Rider types", y = "Ride count")

Once again, you need to include code for loading your data into memory in your Rmd file itself. The Rmd documents gets knitted on a clean environment where the data you have loaded interactively doesn't exist.

Right! I just did that;

Januay_data <- read_csv("Downloads/Capstone Bikeshare/202201-divvy-tripdata.csv")
February_data <- read_csv("Downloads/Capstone Bikeshare/202202-divvy-tripdata.csv")
March_data <- read_csv("Downloads/Capstone Bikeshare/202203-divvy-tripdata.csv")

Followed by this code chunk;

bikeshare_tripdata <- bind_rows(Januay_data, February_data, March_data)

Here's the error message I got when I tried to knit this time:

processing file: Bikeshare.Rmd
  |....                                              |   8% [unnamed-chunk-1]  
Quitting from lines 9-12 [unnamed-chunk-1] (Bikeshare.Rmd)
                                                                                                              
Error in `read_csv()`:
! could not find function "read_csv"
Execution halted

read_csv() comes from the readr package so you need to load it first. Include library(readr) in your file before the lines that load the data into memory or simply use the base R version which is read.csv().

Thank you so much. This worked. I added 'path_to_file' after the loading the 'readr' package and it worked.

Thank you @HanOostdijk @jrkrideau @andresrcs .