pander icon indicating copy to clipboard operation
pander copied to clipboard

NA Values Generate Internal Error in pander for 'Correlation' rapport template

Open gurol opened this issue 8 years ago • 5 comments

rapport function generates internal pander error:

[1] “7” attr(,“class”) [1] “knit_asis” attr(,“knit_cacheable”) [1] NA variables with [1] “286” attr(,“class”) [1] “knit_asis” attr(,“knit_cacheable”) [1] NA cases provided. Internal pander error: zero length argument while running: cm <- cor(vars, use = "complete.obs")

The related code is:

rapport('Correlation', data=dataFrameMetrics(MCC, ACC, FSc1, BACC, Gm, INFORM, MARK), vars=c('MCC', 'ACC', 'FSc1', 'BACC', 'Gm', 'INFORM', 'MARK')

adding use='na.or.complete' parameter does not work either.

gurol avatar Feb 23 '17 06:02 gurol

Can you please share what is dataFrameMetrics? I cannot reproduce and start debugging the problem without knowing what you try to do.

daroczig avatar Feb 23 '17 07:02 daroczig

Please, ignore the example code above. The following codes (Test.R) is a minimal working example:

library(rapport)
library(knitr)
metric1 <- c(1, 2, 3, 4, 5)
metric2 <- c(1, 2, 3, 4, 5)
test <- data.frame(metric1, metric2)
rapport('Correlation', data=test, vars=c('metric1', 'metric2'))

This code works when it runs in R (report is displayed in console). But, when I try to Knit Document in R studio (File | Knit Document, selecting HTML output) it displays errors as partly shown in below:

## # Variable description
## 
## [1] "_2_"
## attr(,"class")
## [1] "knit_asis"
## attr(,"knit_cacheable")
## [1] NA
##  variables with [1] "_5_"
## attr(,"class")
## [1] "knit_asis"
## attr(,"knit_cacheable")
## [1] NA
##  cases provided.
## 
## Internal `pander` error: `argument is of length zero` while running: `cm <- cor(vars, use = "complete.obs")`
## 
## Please [report the issue](https://github.com/Rapporter/pander/issues/new) with a reproducible example to help developers fix this ASAP.
## Internal `pander` error: `argument is of length zero` while running: `diag(cm) <- NA`
## 
## Please [report the issue](https://github.com/Rapporter/pander/issues/new) with a reproducible example to help developers fix this ASAP.

What I found now that it is not related to NA in supplied data (i.e. metric1 and metric2 have no NAs). Therefore, I should say it is related to generating markdown HTML report.

Thank you for your interest.

gurol avatar Feb 23 '17 08:02 gurol

Ah, okay, thanks a lot for the explanation. Well, rapport was never intended to be called within a knitr or R Markdown document, as it's doing something similar to kintr so there's some conflict in the backends.

Can you please provide a use case for this? Maybe we can figure out something on how to fix this.

Meanwhile, if you just want to convert the markdown to eg HTML or PDF, you could try tpl.export from the rapport package, eg:

tpl.export(rapport('Correlation', data=test, vars=c('metric1', 'metric2')))

daroczig avatar Feb 23 '17 09:02 daroczig

Thanks for the clarification and suggesting the export function. I have used it in my study. For the use case, I like rapporter's presentation approach in correlations and wanted to use it inside my report.

gurol avatar Feb 23 '17 12:02 gurol

Thanks for the feedback! I will look into this, but the rapport package is not currently on the top of my priorities, so it might take some time -- I'll try to get back to you on this in a couple of weeks.

daroczig avatar Feb 23 '17 12:02 daroczig