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".
Related
I'm trying to knit chunks that contain errors into an HTML file but without printing the errors — just the chunk.
While trying to solve this, I learned interesting information such as :
Hiding the result of a chunk that doesn't contain errors
Prettying the error
Preventing chunk evaluation
I also found :
Basic chunk options and inputs
and
A controversy about setting error = TRUE or FALSE
While this was useful information for further analysis, I still don't get how to print the chunk without getting the error.
Lets' say I want the following code to be printed in the HTML file, but not the error :
Actual code looks like this (keep in mind that I erased the initial part of the R code so you can see the code) :
include=TRUE, echo=TRUE, message=FALSE, warning=FALSE, error=TRUE, results='hide', warn.conflicts=FALSE}
ggplot(df, aes(y = ABC, x = 123)) +
geom_point()
I am trying to run ConnectedThresholdImageFilter example in ITK mentioned "https://itk.org/Doxygen45/html/Segmentation_2ConnectedThresholdImageFilter_8cxx-example.html" here.
But it is showing the following error.
itk::ImageFileWriterException (0x24cb740)
Location: "void itk::ImageFileWriter::Write() [with
TInputImage = itk::Image]" File:
/usr/local/include/ITK-4.13/itkImageFileWriter.hxx Line: 151
Description: Could not create IO object for writing file output
Tried to create one of the following:
BMPImageIO
BioRadImageIO
Bruker2dseqImageIO
GDCMImageIO
GE4ImageIO
GE5ImageIO
GiplImageIO
HDF5ImageIO
JPEGImageIO
LSMImageIO
MINCImageIO
MRCImageIO
MetaImageIO
NiftiImageIO
NrrdImageIO
PNGImageIO
StimulateImageIO
TIFFImageIO
VTKImageIO You probably failed to set a file suffix, or
set the suffix to an unsupported type
I didn't do any changes in code. And I am trying to use dicom image as an input.
It is either
You set the output file name with an unsupported extension.
There is something wrong about how you compiled/linked ITK or how you are linking your example to ITK.
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 )
{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)