Newly, I have a problem creating a Rmarkdown file (pdf, HTML, etc.) in R. I did not have this problem before, and could create Rmarkdown files without any problem. But now it is about three days that I see the following message (error):
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) :
namespace 'xfun' 0.17 is being loaded, but >= 0.21 is required
Calls: :: ... namespaceImportFrom -> asNamespace -> loadNamespace
Execution halted
Could you please let me know how to solve this error?
Related
I get this error when I run the Knit to HTML of an RMarkdown
"Error in rbind(info, getNamespaceInfo(env, "S3methods")) : number of columns of matrices must match (see arg 2) Calls: :: ... tryCatch -> tryCatchList -> tryCatchOne -> Execution halted"
When I run the RMarkdown chunck by chunck it works, but when I run the Knit no. Do you know how can you help me ?
The qa() function of the ShortRead bioconductor library generates quality statistics from fastq files. The report() function then prepares a report of the various measures in an html format. A few other questions on this site have recommended using the display_html() function of IRdisplay to show html in jupyter notebooks using R (irkernel). However it only throws errors for me when trying to display an html report generated by the report() function of ShortRead.
library("ShortRead")
sample_dir <- system.file(package="ShortRead", "extdata", "E-MTAB-1147") # A sample fastq file
qa_object <- qa(sample_dir, "*fastq.gz$")
qa_report <- report(qa_object, dest="test") # Makes a "test" directory containing 'image/', 'index.html' and 'QA.css'
library("IRdisplay")
display_html(file = "test/index.html")
Gives me:
Error in read(file, size): unused argument (size)
Traceback:
1. display_html(file = "test/index.html")
2. display_raw("text/html", FALSE, data, file, isolate_full_html(list(`text/html` = data)))
3. prepare_content(isbinary, data, file)
4. read_all(file, isbinary)
Is there another way to display this report in jupyter with R?
It looks like there's a bug in the code. The quick fix is to clone the github repo, and make the following edit to the ./IRdisplay/R/utils.r, and on line 38 change the line from:
read(file,size)
to
read(size)
save the file, switch to the parent directory, and create a new tarbal, e.g.
tar -zcf IRdisplay.tgz IRdisplay/
and then re-install your new version, e.g. after re-starting R, type:
install.packages( "IRdisplay.tgz", repo=NULL )
When I try a bunch of chunks in RStudio I get the following error in RStudio:
|.................................................................| 100%
ordinary text without R code
output file: relatorio1.knit.md
Error in extract(input_str) : Invalid nesting of html_preserve directives
Calls: <Anonymous> ... <Anonymous> -> base -> extract_preserve_chunks -> extract
I really could not identify what is going on since the debugger tells me nothing and the code runs until 100%, but it simply does not generate the html file as it was supposed to.
I see that this error comes from htmltools package code (see https://github.com/rstudio/htmltools/blob/master/R/tags.R), which says:
# Sanity check.
if (any(preserve_level < 0) || tail(preserve_level, 1) != 0) {
stop("Invalid nesting of html_preserve directives")
}
Unfortunately I cannot provide the whole Rmd file since it is work related, but generic comments on this issue are welcome.
Thanks.
Edit: I tried to circumvent the problem by isolating datatables (package DT) that were not working. I am using data.table's fread funtion, but I also tried readr and base data.table. I also tried to load data directly from source (source file generates data). When I try to knit it, I still get the above error. Never had any problem with these functions before.
I try the following code:
---
title: "Title"
output: flexdashboard::flex_dashboard
---
```{r setup}
require(DT)
require(flexdashboard)
require(htmltools)
require(htmlwidgets)
require(readr)
require(data.table)
source("sourcefile.R")
a <- fread("perfectlynormaldata.txt")
b <- a[,1:10]
```
Flexdashboard Storyboard {.storyboard}
=========================================
### Text Text
```{r datatable not running}
datatable(b)
```
Edit 2: I could render the datatable after limiting the length of a string variable with substr. I don't know if it was supposed to happen.
Final Edit: I could solve definitely the issue by removing certain characters that appear in the problematic variable as "\032".
{r,eval=F}
corfit <- duplicateCorrelation(brain.rma, design.trt, block = blocks)
{r histOfcorrelations}
print(cor)
{r}
plot(hist(tanh(corfit$atanh.correlations)))
My codes run just fine in the RMD file, but will not knit to HTML.
Error in hist(tanh(corfit$atanh.correlations)) : object 'corfit' not
found Calls: ... withCallingHandlers -> withVisible ->
eval -> eval -> plot -> hist Execution halted
Any suggestions?
Thanks!
I think that it might be because your statement eval=F.
This in fact makes knitr not to evaluate corfit and then the object can't be found.
Try to delete eval=F and see what happens!
You need to remove your code: "eval=F"
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
I have a pretty long R code that takes approx 2-3 hours to run and Knit to HTML. However even with minor errors or warning.. the Knit aborts.. In the below example it has done so due to savehistory error.
processing file: model_v64.Rmd
|...................... | 33%
ordinary text without R code
|........................................... | 67%
label: unnamed-chunk-1 (with options)
List of 1
$ echo: logi TRUE
Quitting from lines 21-278 (model_v64.Rmd)
**Error in .External2(C_savehistory, file) : no history available to save**
Calls: <Anonymous> ... withCallingHandlers -> withVisible -> eval -> eval -> savehistory
Execution halted
Is there any way in which we can
Option 1 - Recover the partially created HTML from tmp directories or anywhere else
Option 2 - Get Knit HTML to continue on errors and not halt the code.
Option 3 - atleast save the already Knit HTML and then stop.
Thanks, Manish
Set the chunk option error = TRUE to display the error instead of halting R:
knitr::opts_chunk$set(error = TRUE)