Rapporter / pander

An R Pandoc Writer: Convert arbitrary R objects into markdown
http://rapporter.github.io/pander/
Open Software License 3.0
294 stars 66 forks source link

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

Open gurol opened 7 years ago

gurol commented 7 years ago

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.

daroczig commented 7 years ago

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

gurol commented 7 years ago

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.

daroczig commented 7 years ago

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')))
gurol commented 7 years ago

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.

daroczig commented 7 years ago

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.