Problems with knitting

Hi everyone,

I'm new to RStudio and have issue with knitting a R markdown file to pdf. every time I try, I get an error of couldn't function. however when I run the code It works normally. The issue only appears when I try knitting.

Your help is highly appreciated :slightly_smiling_face: :slightly_smiling_face:

Hi @Mohamed_Fergany ,
For best help you, it's necesary put more information about his problem. In this form the community could help you.
Maybe the error msm, or take a clear picture.

Thanks for your interest. Here's the error message

Error in penguins %>% group_by(island) %>% count(species) : 
  could not find function "%>%"
Calls: <Anonymous> ... handle -> withCallingHandlers -> withVisible -> eval -> eval
Execution halted

It does the same for any other function also. However as I said before the code itself runs without any issues

1 Like

Try to activate all library before run the code.
This msm show a problem with pipe %>%

# Remember activate all library of his code and next knirt.
1 Like

already did. that's why I mentioned that code runs without any issues

Would you show a fragment of your document, please?

Invocation of the libraries shall came from chunk as well, like:

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

Sure , this is the first part of it

pdf_document: default
word_document: default
html_document: default

# Load the dataset

# A draft to check the plots results
summary = penguins %>%
  group_by(island) %>%

Note that every plot in the gglpot package must start with the ggplot() function
where you specify the dataset.

Bar plots can be used to show the count of each categorical value in one
variable only. If we want to used the bar plot for two variables, we use the
column chart. However it's better to use scatter plots and heat maps. Let's try
this simple column & scatter plots to see the difference.

ggplot(penguins) + geom_col(mapping = aes(flipper_length_mm, body_mass_g))
ggplot(penguins) + geom_point(mapping = aes(flipper_length_mm, body_mass_g))

any ideas?


Please assume .Rmd file is a text file. Every R code which have to be executed, has to be wrapped in so called chunks which are marked as


See below. Just remove > signs, which are added by citation function.

> ---
> title: "Untitled"
> output: pdf_document
> ---
> ```{r setup, include=FALSE}
> knitr::opts_chunk$set(echo = TRUE)
> library(palmerpenguins)
> library(tidyverse)
> library(ggplot2)
> ```
> ## R Markdown
> This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <>.
> ```{r penguins}
> data("penguins")
> # A draft to check the plots results
> summary = penguins %>%
>   group_by(island) %>%
>   count(species)
> summary
> ```
> ## Including Plots
> You can also embed plots, for example:
> ```{r pressure, echo=FALSE}
> ggplot(penguins) + geom_col(mapping = aes(flipper_length_mm, body_mass_g))
> ```

Please note, that in .Rmd you can write any sentence outside chunk without # comment tag. In markdown # is used to create paragraphs and subparagraphs.

1 Like

You might have loaded tidyverse interactively in your current working environment and that is why the code runs normally there but you must have in mind that when you knit an Rmd document the code gets executed in a clean environment other than the one you are currently working on so if you have not included the required library calls in your Rmd file itself, the libraries are not going to be loaded on that environment and the knitting is going to fail.

1 Like

I did added the library functions and it finally worked. many thanks for your help AndrΓ©s :+1: :+1:

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.