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

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

Related

Running pivot_longer() while knit Rmd always reports an error

I wrote a very simple R code and it also works fine when I run R-chunks direct in Rmd.
library(tidyr)
AirPassengers <- AirPassengers %>%
pivot_longer(-year, names_to = "month", values_to = "passengers")
But as soon as I try to knit this Rmd file, the following error is reported. Why is this and what does it mean to report an error?
Error in UseMethod("pivot_longer") :
no applicable method for 'pivot_longer' applied to an object of class "list"
Calls: <Anonymous> ... withCallingHandlers -> withVisible -> eval -> eval -> %>% -> pivot_longer
In addition: Warning messages:
1: replacing previous import 'lifecycle::last_warnings' by 'rlang::last_warnings' when loading 'pillar'
2: replacing previous import 'lifecycle::last_warnings' by 'rlang::last_warnings' when loading 'tibble'
3: package 'pammtools' was built under R version 4.0.5
4: In AirPassengers$year <- as.numeric(rownames(AirPassengers)) :
Coercing LHS to a list
Execution halted
Any help would be greatly appreciated!
I googled and didn't find any useful answers.
I'm curious why it works fine in the current chunk and gets the desired result but not in knit.
Also: the line referred to in the error report is only the code to load the package tidyr.

R markdown: Error in FUN(X[[i]], …): cannot coerce type 'symbol' to vector of type 'double'

Even though I can run my code without a problem, when I was trying to knit the markdown file into HTML, these two simple lines of code give me this error:
R markdown: Error in FUN(X[[i]], …): cannot coerce type 'symbol' to vector of type 'double' Calls: ... WithVisible -> eval -> eval -> data.frame -> apply Execution halted
sapply(data, levels)
numdata <- data.frame(lapply(data, as.numeric))
Does anyone know why it happens and how to solve it? I would be very grateful for your help
Thanks #Allan and #quickreaction. The data was given in a Rdata file. So when I opened it, it loads into my Global Environment. It doesn't satisfy the condition that "markdown document is a standalone self-referential code environment"
I solved it by including
write.csv(data,'data.csv')
data<-read.csv('data.csv')

Error in UseMethod("select_") in Blogdown

I am using Blogdown to create a new post and I am getting the following error when trying to preview.
The code works well in my Rmarkdown file but I cannot update it to my blog. Do anyone know where the problem is?
Quitting from lines 36-47
Error in UseMethod("select_") :
no applicable method for 'select_' applied to an object of class "function"
Calls: local ... freduce -> -> select -> select.default -> select_
Execution halted
Here is my code in lines 36-47;
library(corrplot)
library(RColorBrewer)
library(tidyverse)
corrplot(cor(df %>% select(Sales, Customers, Store,
Open, SchoolHoliday,
DayOfWeek, month, year,
CompetitionDistance,
Promo, Promo2_active) %>%
filter(!is.na(Sales), !is.na(CompetitionDistance))),
type="upper", order="original",
col=brewer.pal(n=8, name="RdYlBu"))
Thanks a lot.
I think you're getting this error because you don't have an object called df in your global environment. Either your data frame hasn't been created yet or it is called something else. There is a little-known function called df in the stats package, which is on the search path when you start an R session. You can check this by starting a new R session and typing df into the console. You will see the body of the function stats::df.
You are therefore getting the error because you are trying to subset a function, not a data frame. To resolve the error, make sure you create a data frame called df before your call to corrplot

Knitr error in loading in-built data

I am trying to run a code in R using knitr compiler. It for some reason generates this error:
Error in str(Oats) : object 'Oats' not found
Calls: <Anonymous> ... withCallingHandlers -> withVisible -> eval -> eval -> str
Execution halted
Here is the code I am using:
```{r}
data(Oats)
str(Oats)
plot(Oats)
sp.oats <- within(Oats, nitroF <- factor(nitro))
model1=lm(yield~Variety*nitro,data=Oats)
summary(model1)
model2=lme(yield~Variety*nitro,data=Oats,random=~1|Block/Variety/nitro)
summary(model2)
coef(model1)
coef(model2)
plot(ranef(model2))
plot(model2)
```
Please suggest what I should do to resolve this issue. Thanks!
I think you're looking for
data(Oats,package="nlme")
Quotation marks are optional around the data set name (Oats, "Oats") but mandatory for the package name ("nlme").
But
library(nlme)
data(Oats)
will also work, and since you're going to be using functions from nlme anyway, you might as well do it that way.
Adding comment as an answer. I thought it might be a duplicate (ansd still suspect it might be, but I couldn't find it in a search, so maybe it will be useful in subsequent searches.:
It is in the nlme-package which is not loaded by default, but it is shipped with every copy of R since its priority is "recommended". #MAPK should add a line that says data(Oats, pac=nlme) before he tries to access it, and hpesoj626 should try that at his console. Of course, that will then possibly lead to another error since the lme-function might not be there. So I think the final solution might be
```{r}
library(nlme)
data(Oats)`
....
as a starting point (inside the knitted section).

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