I am a new user to RStudio, and have encountered an error when using a .rmd file and Knit HTML
If I have an install.packages line:
install.packages('ggplot2');
library(ggplot2);
when I click Knit HTML, an error is returned:
Error in contrib.url(repos, "source") : trying to use CRAN without setting a mirror calls: ... withVisible -> eval -> eval -> install.packages -> contrib.url Execution halted
I was able to work around this using:
if (!require('ggplot2'))
{
install.packages('ggplot2');
library(ggplot2);
}
If I'm writing a .rmd, do I need to use the if (!require(
line every time I install a new package? Is there a way to avoid this so I can write install.packages(
only?
No Knit HTML button This means that RStudio doesn't understand your document is supposed to be an RMarkdown document, often because your file extension is . txt . To fix this, go to the Files tab (lower right corner, same pane as Plots and Help) and select the checkbox next to your document's name.
Changing the configuration in R Studio to solve install packages issue. Go To Tools -> Global option -> Packages. Then uncheck the option “Use secure download method for HTTP”. For other RStudio issues refer to official Troubleshooting Guide here.
If you are using RStudio, then the “Knit” button (Ctrl+Shift+K) will render the document and display a preview of it.
You don't need install.package()
line everytime.
Normally you should install packages in console or a separate interactive session or delete that line after installation of that library (here it's ggplot).
Just use library(ggplot2)
library(ggplot2);
Hope it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With