code chunks running but failing to knit

I have created an Rmarkdown file in which all the code chunks run properly without errors but when I knit I am getting the following error message: "Line 53 Error in metals(.) could not find function "metals""

"metals" refers to what I named the dataset I am working with and the code for this is as follows:

metals = read_excel("path/data.xlsx") %>%
  janitor::clean_names()

This runs without error when knitted. The knitting process halts at line 53 which I have coded as follows:

metals %>%
 ggplot(aes(x = col1)) + 
 geom_histogram()

When I run this chunk it produces a histogram with no errors. I have the most recent Rstudio and base R packages, and I have updated all my packages and libraries. I am really at my wit's end trying to figure this out and any help would be appreciated, thank you.

I have tried uninstalling and re-installing Rstudio and base R, updating all my libraries and packages, and changing the working folder but none of this has worked. The libraries I have loaded in the Rmd file are tidyverse, formatR, readxl, and ggridges.

The error message you mention suggests the previous line of code is not present in your Rmd file itself or it is not being executed when knitted.

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 frame doesn't exist there. You need to include the necessary code to import the data frame into memory, in your Rmd document itself.

If this doesn't solve your problem, please provide a proper REPRoducible EXample (reprex) illustrating your issue.

I have created an Rmarkdown file in which all the code chunks run properly without errors but when I knit I am getting the following error message: "Line 53 Error in metals(.) could not find function "metals""

"metals" refers to what I named the dataset I am working with and the code for this is as follows:

metals = read_excel("path/data.xlsx") %>%

janitor::clean_names()

This runs without error when knitted. The knitting process halts at line 53 which I have coded as follows:

metals %>%

ggplot(aes(x = col1)) +

geom_histogram()

When I run this chunk it produces a histogram with no errors. I have the most recent Rstudio and base R packages, and I have updated all my packages and libraries. I am really at my wit's end trying to figure this out and any help would be appreciated, thank you.

I have tried uninstalling and re-installing Rstudio and base R, updating all my libraries and packages, and changing the working folder but none of this has worked. The libraries I have loaded in the Rmd file are tidyverse, formatR, readxl, and ggridges.

Does it works when doing

ggplot(metals, aes(x = col1)) +
geom_histogram()

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.