I'm running into some issues while knitting an RMarkdown document that reads in a large raster. The code chunk runs without error in the console, but fails when I try and knit the markdown document.
Here is the line in the document that produces the error:
r <- raster("./data/very_large_raster.img")
Error in if (x == "" | x == ".") { : argument is of length zero
Calls: <Anonymous> ... raster -> raster -> .local -> .rasterObjectFromFile
Execution halted
Related
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!
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
download.file function for multiple files works fine in console. It will return error when I click knit in RStudio to compile the code as a chunk of rmarkdown file.
Here is an example Rmd file and the code is
options(timeout=600)
# Download demo data from figshare
name <- c('1.mzML','2.mzML')
url <- c("https://ndownloader.figshare.com/files/25521071","https://ndownloader.figshare.com/files/25521074")
download.file(url, name)
The code works fine in the console and will download two files. However, it will generate error in Rmd files when click knit in RStudio and the error is:
Quitting from lines 10-15 (download.Rmd)
Error in download.file(url, name) :
'url' must be a length-one character vector
Calls: <Anonymous> ... withCallingHandlers -> withVisible -> eval -> eval -> download.file
Execution halted
A temporary solution is using for loop:
options(timeout=600)
# Download demo data from figshare
name <- c('1.mzML','2.mzML')
url <- c("https://ndownloader.figshare.com/files/25521071","https://ndownloader.figshare.com/files/25521074")
for(i in c(1:2)){
download.file(url[i], name[i])
}
I am sure it's not an issue from knitr package because the following code will work:
knitr::knit('download.Rmd')
However, I wonder why download.file doesn't work for multiple files in RStudio by clicking knit button?
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!
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
```