I am trying to use the two packages afex (easy anovas) and rempsyc (easy APA formatting for tables) in my R code. Independently, both work nicely. I use rempsyc's function nice_table to create a table in APA formatting that can be exported to Word but also seen in the RStudio Viewer, like this:
Once I load afex though, this function from rempsyc doesn´t show me a table anymore and instead gives me the following output:
[1] header body footer col_keys caption blanks properties
<0 rows> (or 0-length row.names)
To reproduce this issue, here´s a basic example based on mtcars that is also used for demonstration of rempsyc.
library(rempsyc)
nice_table(
mtcars[1:3, ],
title = c("Table 1", "Motor Trend Car Road Tests"),
note = c(
"The data was extracted from the 1974 Motor Trend US magazine.",
"* p < .05, ** p < .01, *** p < .001"
)
)
#this one works
library(afex)
nice_table(
mtcars[1:3, ],
title = c("Table 1", "Motor Trend Car Road Tests"),
note = c(
"The data was extracted from the 1974 Motor Trend US magazine.",
"* p < .05, ** p < .01, *** p < .001"
)
)
#this one gives the error above and no table is created
detach("package:afex", unload = TRUE)
nice_table(
mtcars[1:3, ],
title = c("Table 1", "Motor Trend Car Road Tests"),
note = c(
"The data was extracted from the 1974 Motor Trend US magazine.",
"* p < .05, ** p < .01, *** p < .001"
)
)
#still doesn´t work
As you can see, my first solution was to unload afex to make this work again, but the same error remains. Specifying the package (rempsyc::nice_table) also doesn´t work. The only way I can get the function "nice_table" to work again is to close R/RStudio completely and restart from the top.
I think the problem is within the nice function from afex that outputs a dataframe of the class nice_table (as the manual states). This somehow seems to overwrite some default method that allows the function nice_table to work.
I am basically just asking if anyone knows a way that these two packages might still work together in one script. Maybe I have missed something. Thank you in advance!

Edit: In the development version of
rempsyc, I have now removed thenice_tableclass completely, so you should be able to install the new version from the r-Universe without having to usepkgload::unloadin your script. The new version will find its way to CRAN eventually.Old answer
I am the
rempsycpackage maintainer. Thank you for reporting this issue. I have opened an issue within theafexrepository to find a solution to this colliding namespace. This will hopefully be resolved in a future version ofafex.In the meanwhile, I provide an explanation of this issue below, as well as a workaround using
pkgload::unloadinstead ofdetach, which you can use within your script for the time being.Workaround
Created on 2024-02-22 with reprex v2.0.2
Explanation
The
afexpackage has a printing method for objects of classnice_table(for theafex::nice()function), and, of course,rempsyc::nice_table()also produces an object of classnice_table.The specific issue is that
afex:::print.nice_table()usesprint.data.frame(x)on thenice_tableobject, but then does not return theflextable, or rather, return it invisibly, withinvisible(x)(as seen on these code lines).I think there is nothing I can do from my side (besides giving up on the
nice_tableclass) becauseafexoverwrites the printing method for this class without much robustness checks to avoid this type of conflict. Hopefully we will find a solution soon.The workaround of
pkgload::unloadworks because, unlikedetach, it detaches the whole namespace. You can just loadafexagain later in the script if you need to and repeat these steps as needed.