RMarkdown not knitting correctly, "could not find function %>% error"

Hello,

I tried following a previous thread, Knitr: could not find function %>% error, but couldn't seem to resolve my issue. The code runs correctly in the console, but when I go to knit I keep getting could not find function "%>%" error.

I'm concerned I could have too many packages loaded. Below is my best attempt at a reprex. I apologize... I was unsure how to create a data frame out of a datetime object.

library(tidyverse)
library(dplyr)
library(lubridate)
library(readr)
library(ggplot2)
library(DataExplorer)
library(purrr)
library(funModeling)
library(data.table)
library(readxl)
library(readr)
library(arules)
library(arulesViz)
library(magrittr)
library(forcats)
library(agricolae)
library(knitr)

# Sample data frame

dta_samp<-data.frame(
  InvoiceNo = c( 536366, 2010-12-01 08:28:00),
  InvoiceDate = c(536367,    2010-12-01 08:34:00)



dta_samp_fix <- dta_samp %>% 
  mutate(day = parse_date(format(InvoiceDate, "%Y-%m-%d")),
         day_of_week = lubridate::wday(day, label = FALSE),
         time = parse_time(format(InvoiceDate, "%H:%M")),
         month = format(InvoiceDate, "%m"))

# Below is the error I get from R Markdown

#Quitting from lines 157-175 (Affinity_Analysis_UK_eCommerce.Rmd) 
#Error in retail %>% mutate(day = parse_date(format(InvoiceDate, "%Y-%m-%d")),  : 
#                             could not find function "%>%"
#                           Calls: <Anonymous> ... handle -> withCallingHandlers -> withVisible -> eval -> eval

#      Execution halted

1st issue noticed: missing right parentheses at the end..
2nd: dates should be in quotes

Also, tidyverse includes a lot of the packages you are calling individually, so you should remove those calls. You can see which packages get loaded when you execute library(tidyverse).

> library(tidyverse)
-- Attaching packages --------------------------------------- tidyverse 1.3.0 --
v ggplot2 3.3.0     v purrr   0.3.4
v tibble  3.0.0     v dplyr   0.8.5
v tidyr   1.0.2     v stringr 1.4.0
v readr   1.3.1     v forcats 0.5.0

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