Code runs fine in R but Knit shows an error - r

I'm having a problem with the following code in an Rmd file, the problem is that if I run the commands in the console, the code runs perfectly fine, and also there is no mistakes in the syntax, I have change several styles but I'm still receiving the same error when I knit the file.
Raw_Data96_11$EVTYPE <- as.character(Raw_Data96_11$EVTYPE)
List_Events <- count(Raw_Data96_11, vars = "EVTYPE")
List_Events <- arrange(List_Events,desc(n))
List_Events <- mutate(List_Events, percentage = trunc((100*(n/653530))))
Top_10_Events <- List_Events[1:10,2:3]
I had to change the syntax for count, when I run the command in the console, I did not had to use vars, but now I cannot run the command arrange, this is the error :
Quitting from lines 98-117 (PA_2_Reproducible_Research.Rmd)
Error in order(List_Events$n) : argument 1 is not a vector
Calls: ... withVisible -> eval -> eval -> arrange -> eval -> eval -> order
Execution halted
I have included the libraries in that chunk but I'm still receiving an error, does anyone know what is going, is it the syntax or what else do I need to do?

Related

External source script not working while knitting the rmarkdown into document

I have large function in another R script. when I used it as a source and call the function, it is working fine but it does not work if I try to knit it into document.
line73 source('PATH\\function.R', local = knitr::knit_global())
line74 table1 <- demograph(arg1, arg2)
here , demograph() is the function from external R scriptfunction.R
I can get the results in the console but while trying to knit it to document I got following error:
Quitting from lines 73-81 (vision_rmd.Rmd)
Error in eval(x, envir = envir) : object 'False' not found
Calls: <Anonymous> ... eval_lang -> in_input_dir -> in_dir -> eval -> eval
Execution halted

Object: "DF" not found when knitting rmd

I get this error when knitting any rmd. file using this data set (Aviste_Affect_Data).(The problem also happens with other data frames when I tried to reproduce the problem) All of the code within the files run and the data set itself appears to be fine (it was imported from SPSS). The error occurs on the first line of code in each rmd. file and if I delete that line the error just happens again on the next line of code and so on.
This is the first line of code that the error occurs on, which again runs fine (the package dplyr is being used):
Data_na2014<-Aviste_Affect_Data %>% filter(!Year==14)
Error Message:
Error in eval(las, parent, parent) : object 'Aviste_Affect_Data' not found Calls: ...withCallingHandlers -> withVisible -> eval -> eval -> $>$ ->eval ->eval Execution halted
If I try different code as the first code, the error is mostly the same:
Aviste_Affect_Data$Worry<-as.numeric(Aviste_Affect_Data$x78)
Error Message:
Error in eval(expo,envir,enclos) : object 'Aviste_Affect_Data' not found Calls: ...handle-> withCallingHandlers -> withVisible -> eval -> eval Execution halted

How to resolve this Error when knit markdown

I'm trying to knit an RMarkdown to an HTML file.
But I got an error like this
Quitting from lines 28-34 (learning_map2.Rmd)
Error in slot(p, "Polygons") :
cannot get a slot ("Polygons") from an object of type "NULL"
Calls: ... createSPComment -> lapply -> FUN -> sapply -> lapply -> slot
Execution halted
screenshot_1598604180|690x133
But I can run it on my mac. It's just doesn't run in my Window PC.
Thanks all!

Getting error: "Error in table(x0) : object 'PONDICE' not found" while trying to knit

Apologies if this has been answered already. I tried to find a solution that would help, but I was not lucky. I have several data set which I took from the CD that came with my textbook. When I run my code in R, there are no problems. When I try to knit (word, pdf, and HTML), I get the error message: Quitting from lines 20-26 (hw1math424_3.Rmd)
Error in table(x0) : object 'PONDICE' not found
Calls: <Anonymous> ... withCallingHandlers -> withVisible -> eval -> eval -> tab1 -> table
Execution halted.
library(epiDisplay)
tab1(PONDICE$icetype, sort.group = "decreasing", cum.percent = TRUE)
This produces a nice bar graph in R, but wont knit. I have all the files saved to a desktop folder. Please Help! These files came from Regression Analysis (7th edition) Please ask if you need more info!

Knitting returns parse error

In attempting to knit a PDF. I'm calling a script that should return two ggplots by calling the chunk:
```{r, echo=FALSE}
read_chunk('Script.R')
```r
But receive the error
processing file: Preview-24a46368403c.Rmd
Quitting from lines 9-12 (Preview-24a46368403c.Rmd) Error in
parse(text = x, srcfile = src) : attempt to use zero-length
variable name Calls: <Anonymous> ... <Anonymous> -> parse_all ->
parse_all.character -> parse Execution halted
The script on its own runs and returns the two plots, but won't return them when knitted.
Similarly attempted to use source()
But got a similar error
Quitting from lines 7-10 (Preview-24a459ca4c1.Rmd) Error in
file(filename, "r", encoding = encoding) : cannot open the
connection Calls: <Anonymous> ... withCallingHandlers -> withVisible
-> eval -> eval -> source -> file Execution halted
While this does not appear to be a solution for you, this exact same error message appears if the chunk is not ended properly.
I experienced this error and traced it to ending chunk with `` instead of ```. Correcting the syntax of the chunk solved the problem I experienced with the same error message as you.
Are you sure that knitr is running from the directory you think it is? It appears that it is failing to find the file.
use an absolute path, if that fixes it, you've found your problem
once you've done that, you can use opts_knit$set(root.dir = "...") -- don't use setwd(.) if you want it (the cwd) to be maintained.
Knitr's default is the directory of the .Rmd file itself.
It may have to do with the "r" at the end of the triple backquotes demarcating your code chunk. There should be nothing after the triple backquotes, but I think the problem is specifically that the letter is "r".
The issue stems from the fact that R markdown processes backquoted statements starting with r as inline code, meaning it actually runs whatever is between the backquotes.
I had similar issues writing a problem set in an Rmd with this statement, which had backquoted text intended to be monospace but not run as inline code:
Use sapply or map to calculate the probability of a failure rate over r <- seq(.05, .5, .025).
When I knit the document, I got opaque error messages saying I had an improper assignment using <-. It was because instead of just displaying the backquoted statement in monospace, r <- seq(.05, .5, .025) was actually processed as R inline code of <- seq(.05, .5, .025)...thus the improper assignment error. I fixed my error by changing the variable name from r to rate.
The actual text of the error message in your question might refer to whatever follows your code chunk, as the knitting process is probably trying to run that as code. In this case, just removing that stray r at the end of the code chunk should fix the error.
You should use the following similar syntax, I had the same exact issue but got it fixed:
```{r views}
bank.df <- read.csv("C:/Users/User/Desktop/Banks.csv", header = TRUE) #load data
dim(bank.df) # to find dimension of data frame
head(bank.df) # show first six rows
```
the ``` has to be in the end of the line.
In my case was that I finished the code with four comas, not three . Check this and If you finished with four comas too, try to delete one of them.

Resources