Can't Knit R Markdown File When I Use ggplot with it - r

I'm currently doing an R Markdown File of an analysis I recently finished using R. With that, whenever I add details, I click Knit to ensure everything I added goes well on the HTML knit file.
I noticed that when I used ggplot on my R Markdown file, the file doesn't knit anymore and it says:
Error while opening file - No Such File or directory.
But when I deleted the ggplot command, it gets knitted again.
But this time, without the visualization, it gets knitted again.
UPDATE: I see this error message on the console tab everytime I use ggplot on my .rmd file.
So with that, I call on install.packages("ggplot2") & library("ggplot2") on my .rmd file. However, I get this error instead.
How will I be able to retain the ggplot command and at the same time be able to knit the file? As an added reference, the ggplot command executes on the .rmd file, it just doesn't knit. Can someone help me please?

Related

Bad file argument when knitting markdown file

I always get a "bad file error" when trying to knit a markdown file
Does anyone know how to fix it?
Haven't tried much, tried loading the file again. Didn't work.
I'm using r cloud, and I had to upload the file directly in "enviroment", but i was able to use the dataset.

R Markdown: the code chunks run, but getting errors when knitting

I'm using RStudio Cloud. I'm running an RMarkdown doc, when I run the code chunks in the doc they work fine, but when I'm trying to knit I get errors. Before I used the code "knitr::opts_chunk$set(error = TRUE)" the doc wouldn't knit at all (error message was saying objects couldn't be found); now it knits BUT I get the error message "## Error in .External2(C_dataviewer, x, title): unable to start data viewer" when I try to View(dataframes) that I've created (the data frames I created show up in the global environment but not in my file path directory, which is /cloud/project). I'm guessing that RMarkdown can't find these since they are in a different file path? I'm also assuming that files in the global directory aren't available for RMarkdown to knit, so how do I get them to be available for RMarkdown to knit? Thank you!
Instead of doing View you can just do this.
```{r}
df # assuming df is your data.frame object name
```
this will print your whole dataframe df in the knitted document.

Run only R commands in rmd file

I have a large Markdown file (*.Rmd) and want to execute only the R commands in that file (not the text) in RStudio. How can this be done?
If I mark the whole document and try to execute it, R tries to execute also the text in the Markdown file, which, of course, results in errors.
Click on the arrows at the top right of the chunks:

spin and "Compile Report' do not convert R script to Rmd in RStudio Preview

I want to use spin() function for my R script to produce rmarkdown .Rmd file. Instead, RStudio returns .md file. This happens in RStudio Preview version 1.1.331.
My R file is from https://github.com/yihui/knitr/blob/master/inst/examples/knitr-spin.R. I downloaded it and put inside my working dir. I then typed spin("test.R", format = "Rmd") in the Console pane.
When I clicked enter, in the console, it showed processing file:knitr-spin.Rmd then output file: knitr-spin.md. Then knitr-spin.html and knitr-spin.mdwere visible, but there was no knitr-spin.Rmd in the working folder.
For the next try,
I clicked the Compile Report button
I chose MS Word outputs
Unfortunately, I still received a folder and an html file and no .Rmd file. Not even .md file was created.
The last time I used spin() or Compile Report was inside RStudio 1.0.153 and it worked nicely and I got .Rmd files, html and MS Word files.
What have I done wrong or I missed?
This should work:
spin("file.R", knit = FALSE) # convert to Rmd only
According to the documentation, argument spin appears to be what you're after:
precious
logical: whether intermediate files (e.g., .Rmd files when format is "Rmd")
should be preserved; default FALSE if knit == TRUE and input is a file
Next to the Knit button there's a sprocket. Click on the Advanced tab and check "Keep markdown source file".

Knit2html not replicating functionality of Knit HTML button in R Studio

I'm trying to write a Bash script in Ubuntu 10.04 that opens a Python file which exports a CSV, and then runs the following Rscript with the goal of exporting a HTML with plots from Dashboard.Rmd:
require(knitr)
setwd('/home/sensors/Desktop/')
knit2html('Dashboard.Rmd')
browseURL('Dashboard.html')
Dashboard.Rmd is an R markdown that calls read.csv on the csv from the first step, makes a data frame and creates plots, but that part's working fine. According to this, I figure that Rscript should replicate the action of pressing "Knit HTML" in R Studio. However, the html it creates is identical to the last time Knit HTML was pressed; i.e. even if the CSV is different, the html doesn't reflect the change.
I also tried using a separate line for knit and markdownToHTML with the same effect. It seems like it doesn't source the code from the Rmd when performing knit. It does update the html properly when I enter the commands from that Rscript into the console of R Studio with Dashboard.Rmd open. However I'm not sure how to translate that into a Bash script. I also tried knit2html with envir=new.env(), envir=R_GlobalEnv, and envir=parent.frame() with no luck. Any help would be appreciated!
So it turns out that this was an artifact of cache=TRUE -- the HTML file was not changed because everything was cached.

Resources