Errors During R Notebook Compilation - r

How to resolve the following errors occurring when compiling/knitting R Notebook into a document? All the required packages are successfully loaded, still, the issue persists.
I restarted RStudio several times. Loaded all the necessary packages. Explored several websites for the resolution, but in vain.
Code:
# pipe operator
x<-5:15
mean(x)
x%>%mean
sum(z,na.rm=TRUE)
z%>%sum(na.rm=TRUE)
sum(is.na(z))
z%>%is.na%>%sum
mean(is.na(z))
z%>%is.na%>%mean
Output:
|................................... | 67% (unnamed-chunk-1)
processing file: qwerty.Rmd
Quitting from lines 13-124 (qwerty.Rmd)
Error in x %>% mean : could not find function "%>%"
Calls: <Anonymous> ... withVisible -> eval_with_user_handlers -> eval -> eval
Execution halted
Code:
data(diamonds)
View(diamonds)
# base histogram(s)
hist(x=diamonds$carat,main="FREQUENCY vs. CARAT",xlab="carat",ylab="frequency")
# base scatter plot(s)
(plot(x=diamonds$carat,y=diamonds$price,xlab="carat",ylab="price"))
Output:
|................................... | 67% (unnamed-chunk-1)
processing file: qwerty.Rmd
Quitting from lines 13-24 (qwerty.Rmd)
Error in as.data.frame(x) : object 'diamonds' not found
Calls: <Anonymous> ... eval_with_user_handlers -> eval -> eval -> View -> as.data.frame
Execution halted

The error is "Error in x %>% mean : could not find function "%>%""
Try to add library(tidyverse) before this code (you need to load all the required packages in the .Rmd file so it can knit)
Also, you will be able to use the diamonds dataset
Hope this can help you!

Related

Error in R Markdown: could not find function "split_chain"

Hello I am using R markdown and have ran into trouble.
When I try to knit this section of my document (the "example" variable is a data frame with a column called "text" which contains strings):
library(qdap)
frequent_terms <- freq_terms(example$text, 4)
frequent_terms
I get this error message:
Error in split_chain(match.callQ), env = env) :
could not find function "split_chain"
Calls: <Anonymous> ... withCallingHandlers -> withVisible -> eval -> eval -> %>%
I have updated Rstudio and the relevant packages(such as magrittr) but I am still running into this issue, one I have never encountered.
How do I fix this error, or how to I interpret the error message, I am at a loss here. Thank you.
According to this issue, your problem should be solved if you add qdap first, and magrittr / tidyverse afterward because gdap uses an old version of the pipe and masks the most recent magrittr version.
However, it is not entirely clear since we do not have a complete reproducible example

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

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!

Trying to Knit but can't because read excel function is not being recognized in R

My whole program is working but when I try to knit to a document the same error is being thrown.
Quitting from lines 3-78 (Untitled.spin.Rmd)
Error in eval(expr, envir, enclos) : could not find function "read_excel"
Calls: <Anonymous> ... handle -> withCallingHandlers -> withVisible -> eval -> eval
Execution halted
I don't under stand why. Where are the first 5 lines of my code.
Dataset_Stats1Project <- read_excel(Users/jamiestokes16/Desktop/Dataset_WomeninGov5.xlsx)
#Descriptive stats for important variables
summary(Dataset_WomeninGov$Wcongress)
summary(Dataset_WomeninGov$Wgov)
summary(Dataset_WomeninGov$Wleg)
Any help would be appreciated.
When you knit a document, knitr essentially creates a new R session for the code to run in. So any packages loaded session will not be accessible unless you load them directly within the .Rmd file.
I always find it easiest to include a chunk at the start of the document loading any packages used:
```{r LoadPackages, include = FALSE}
library(readlx)
# add other packages here
```

Couldnt not find function "cc" Knit PDF in R

When trying to Knit PDF on R Studio i get this error. cc() is a function from package CCA(), which I've installed and loaded previously. It runs perfectly in the console as does this other function: plt.cc(), which needs the same package and library, too.
Quitting from lines 125-128 (Preview-ecc331f1f51.Rmd) Error in eval(expr, envir, enclos) : could not find function "cc" Calls: <Anonymous> ... handle -> withCallingHandlers -> withVisible -> eval -> eval Execution halted
Need some help guys, i'm 'bout to crack my display !
You should do this
require(CCA)
cc(SOMETHING) ...

Resources