Cryptic dplyr error when trying to knit html - r

I have a snippet that depends on a package that I wrote. I'm trying to knit a markdown document and am getting an error:
Error in eval(expr, envir, enclos) : not a vector
Calls: <Anonymous> ... freduce -> <Anonymous> -> bind_rows -> rbind_all -> .Call
The same snippet runs in the console, and the previous line is a lapply that returns a list of data frames. There's confidential data and it'd take a while to come up with a reproducible example so I thought I'd see if others have any tips.

Related

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')

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 fix "Error in eval(expr, envir, enclos) : object 'SUBJECT' not found"?

I am having a hard time knitting my R markdown because of this error
"Error in eval(expr, envir, enclos) : object 'SUBJECT' not found".
I tried rerunning the chunks from the very start but still it did not work. I am still a rookie of R so please bear with my question.
class(SUBJECT)
When I tried to run the chunk no problem occurred but when i tried to knit it, this issue comes in
Quitting from lines 75-76 (exploratory-data-analysis-exercise.Rmd)
Error in eval(expr, envir, enclos) : object 'SUBJECT' not found
Calls: ... handle -> withCallingHandlers -> withVisible -> eval -> eval
Execution halted
you need to check what directory your files are currently stored at using getwd(), Then read your data from there. you should be good.
In case you have : "eval=FALSE" in your R-Markdown chunks, especially the ones that you read your files (ie. read_csv), your codes do not get executed. So, the objects in your following chunks are not recognized. Therefore, remove this code.
eval = FALSE prevents code from being evaluated. (And obviously if the code is not run, no results will be generated). This is useful for displaying example code, or for disabling a large block of code without commenting each line. https://yihui.org/knitr/options/#code-evaluation

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