Knit HTML - Recover from Error? - html

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)

Related

How to solve error in converting to R Markdown

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?

I cannot run the Knit (Knit to HTML) of an RMarkdown

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 ?

Rmarkdown error: Invalid nesting of html_preserve directives

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".

not found Calls: <Anonymous> error when knitting from r studio to HTML

{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

Ignoring attempts to close x with y

Ruby on Rails sometimes gives you annoying "Ignoring attempts to close x with y" warnings arising from assert_select. Often these warnings are the result of invalid HTML, but sometimes they appear even if the HTML is valid. The error in my case looks like this while running ruby test/functional/my_controller_test.rb :
..ignoring attempt to close div with h2
opened at byte 8551, line 207
closed at byte 9554, line 243
attributes at open: {"class"=>"my_css_class", "id"=>"object_1"}
text around open: " \r\n \r\n \r\n \r\n\r\n <div class=\"my_css_class"
text around close: "</a>\r\n </h2>\r\n\r\n <span"
But there is no attempt to close a div with a h2 tag. I tried a HTML validator, but without success. The -W0 parameter mentioned by Giles seems to help - ruby -W0 test/functional/my_controller_test.rb gives no longer a warning, but this does not work for rake test:whatever. What does -W0 do, and how can you avoid using it?
In test helper:
class ActionController::TestCase
include Devise::TestHelpers
Paperclip.options[:log] = false
Mocha::Deprecation.mode = :disabled
#
# kill verbsity
#
verbosity = $-v
$-v = nil
end
There are various command line options for Ruby unit tests. -W does not belong to them, it is a command line option for pure Ruby. As ruby --help says, the ruby -W[level] command line option sets the warning level for Ruby; 0=silence, 1=medium, 2=verbose (default). ruby -W0 sets the warning level to silence.
$ ruby --help
[...]
-w turn warnings on for your script
-W[level] set warning level; 0=silence, 1=medium, 2=verbose (default)
The -W flag also activates the "verbose" mode of Ruby. Mislav has a good explanation of the verbose mode. From within Ruby code, verbosity can be set and tested with the value of the $VERBOSE global variable, which can have 3 states: nil ("0"), false ("1"), and true ("2"). So you can suppress warning for your Test::Unit test by setting
$VERBOSE = nil
in your test_helper.rb. For running RSpecs test you can suppress ruby warning similarly.