0
votes

I have an RStudio session open and need to knit it into an HTML document. I'm trying to do it through the knit button but I'm getting a popup that says this:

Loading required package: knitr Warning message: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘knitr’ Error in knit("jorge_perez_ruano_uber_final.Rhtml", encoding = "UTF-8") : could not find function "knit" Execution halted

knitr terminated with status 1

I have installed the markdown package and also tried to run the render function but it's giving me another error:

Error in render("path/to/file.Rmd") : could not find function "render"

Anyone knows how to help?

1
You need to install knitr, try install.packages("knitr") - mhovd
Thanks for your answer! I did that but it still didn't work. I opened the script as an HTML before starting to type in the code, should I open a regular script and then install the package there with the rest of the code? I've tried both options and neither of them have worked. - Jason
okay now it knits the HTML document but for some reason the output window shows errors, while the output in the console in RStudio is fine and doesn't show any problem. Have you ever encountered a problem like that? - Jason
That is normal - the knitr environment should be considered separate from the global environment, and as such all code you write needs to be in code chunks that will be knitted. - mhovd
Thanks a lot! It worked like a charm! - Jason

1 Answers

1
votes

The error is in the error - you did not have knitr installed.

Install the package with install.packages("knitr"), and you should be ready to go. Remember that the markdown environment should be considered separate from the global environment, and as such you need to load relevant libraries and code in a code chunk before it is accessible. Here is a good introduction to the topic.