crsh / papaja

papaja (Preparing APA Journal Articles) is an R package that provides document formats to produce complete APA manuscripts from RMarkdown-files (PDF and Word documents) and helper functions that facilitate reporting statistics, tables, and plots.
https://frederikaust.com/papaja_man/
Other
652 stars 133 forks source link

Integer values with NA cause error #317

Closed JanaJarecki closed 4 years ago

JanaJarecki commented 5 years ago

Hi, I love papaja, and I think I found a bug. If there is an integer that contains a NA value apa_table throws an error.

To Reproduce

    mytable <- data.frame(a=1:3, b=as.integer(c(1,2,NA)))
    apa_table(mytable)

    # > apa_table(mytable)                                                                                                                       
    # Fehler in if (!check_class == "function" && any(is.na(x))) { :
    # Fehlender Wert, wo TRUE/FALSE nötig ist

The expected behavior is like as if it was a numeric (not an integer)

    mytable <- data.frame(a=1:3, b=c(1,2,NA))
    apa_table(mytable)

If this is intended behavior, maybe a more informative error message would have helped me out a bit! =)

Cheers Jana

-- SessionInfo()

> sessionInfo()                                                                                                                            
R version 3.6.1 Patched (2019-09-13 r77188)                                                                                                
Platform: x86_64-w64-mingw32/x64 (64-bit)                                                                                                  
Running under: Windows 10 x64 (build 18362)                                                                                                

Matrix products: default                                                                                                                                                                                                                  

attached base packages:                                                                                                                    
[1] stats     graphics  grDevices utils     datasets  methods   base                                                                       

other attached packages:                                                                                                                   
[1] papaja_0.1.0.9842      BayesFactor_0.9.12-4.2 Matrix_1.2-17                                                                            
[4] coda_0.19-3            data.table_1.12.2
crsh commented 5 years ago

Hi Jana, thanks for bringing this to my attention. It is indeed not intended behavior and I have just pushed a commit to the development branch. Could you try it out to see if that fixes the issue to you (devtools::install_github("crsh/papaja@devel"))?

JanaJarecki commented 5 years ago

cool thank you :D (integers are weird animals sometimes in R)

I just tried it and the error is gone, however (I am on Windows) the line breaks in the printed table are not printed anymore

library(papaja)
mytable <- data.frame(a=1:3, b=as.integer(c(1,2,NA)))                                                                    
apa_table(mytable)
[1] "\n\n\n\\begin{table}[tbp]\n\n\\begin{center}\n\\begin{threeparttable}\n\n\\begin{tabular}{ll}\n\\toprule\na & \\multicolumn{1}{c}{b}\\\\\n\\midrule\n1 & 1\\\\\n2 & 2\\\\\n3 & NA\\\\\n\\bottomrule\n\\end{tabular}\n\n\\end{threeparttable}\n\\end{center}\n\n\\end{table}\n\n\n"                                                                                          
attr(,"class")                                                                                                             
[1] "knit_asis"                                                                                                            
attr(,"knit_cacheable")                                                                                                    
[1] NA
crsh commented 5 years ago

This is intended behavior because the returned object is of class knit_asis. This ensure, that you don't manually need to set results = "asis" in the chunk option of a chunk in which you call apa_table(). If you would like to inspect the output with line breaks you should be able to do this using cat().

JanaJarecki commented 5 years ago

ah, is this new? I seem to remember that differed in earlier versions if I remember correctly

crsh commented 5 years ago

Yes, this is a fairly recent change: https://github.com/crsh/papaja/commit/04869e06f68911db7f4c7a1cb3dc35bfe1b04533