Comments (7)
Interesting, thanks, will investigate. However, I think this is an issue from the side of afex
, as just loading a package should not silently change behaviour for other packages. Sometimes functions are overwritten but a warning is then printed.
from rempsyc.
Ok, I'm indeed able to replicate this with a simple flextable
and then saving class as nice_table
. The interesting bit is that this issue only arises during interactive use, because the reprex makes it look like it works:
data <- mtcars[1:3, ]
table <- flextable::flextable(data)
class(table) <- c("nice_table", class(table))
table
suppressPackageStartupMessages(library(afex))
table
Created on 2024-02-22 with reprex v2.0.2
While on the interactive console it is actually outputing this:
> table
[1] header body footer col_keys caption blanks properties
<0 rows> (or 0-length row.names)
from rempsyc.
In afex
, nice_table
is a printing method for that class:
## S3 method for class 'nice_table'
print(x, ...)
It is defined as:
print.nice_table <- function(x, ...) {
if(!is.null(heading <- attr(x, "heading"))) {
cat(heading, sep = "\n")
}
print.data.frame(x)
if(!is.null(attr(x, "sig_symbols"))) print_legend(x)
if(!is.null(correction_method <- attr(x, "correction")) &&
correction_method != "none") {
cat("\nSphericity correction method:", correction_method, "\n")
}
invisible(x)
}
This calls print.data.frame(x)
on the flextable object, which gives the output that you are seeing:
data <- mtcars[1:3, ]
table <- flextable::flextable(data)
class(table) <- c("nice_table", class(table))
table
print.data.frame(table)
#> [1] header body footer col_keys caption blanks properties
#> <0 rows> (or 0-length row.names)
Created on 2024-02-22 with reprex v2.0.2
But then it also prevents printing the flextable
, with returning it invisibly with invisible(x)
at the very end.
from rempsyc.
I have opened an issue in the afex repository: singmann/afex#126
from rempsyc.
I have posted a workaround on your stackoverflow question.
Essentially, use pkgload::unload
instead of detach
, which you can use within your script for the time being.
data <- mtcars[1:3, ]
table <- flextable::flextable(data)
class(table) <- c("nice_table", class(table))
suppressPackageStartupMessages(library(afex))
print(table)
#> [1] header body footer col_keys caption blanks properties
#> <0 rows> (or 0-length row.names)
pkgload::unload("afex")
table
Created on 2024-02-22 with reprex v2.0.2
The workaround of pkgload::unload
works because, unlike detach
, it detaches the whole namespace. You can just load afex
again later in the script if you need to and repeat these steps as needed.
from rempsyc.
Thank you for looking into this and for finding an easy workaround!
from rempsyc.
In the development version of rempsyc
, I have now removed the nice_table
class completely, so tomorrow you should be able to install the new version from the r-Universe without having to use pkgload::unload
in your script. I'd have to submit the new version to CRAN, eventually...
install.packages("rempsyc", repos = c(
rempsyc = "https://rempsyc.r-universe.dev",
CRAN = "https://cloud.r-project.org"))
from rempsyc.
Related Issues (19)
- Unable to install HOT 3
- nice_t_test for specific mean? HOT 7
- Logistic regression HOT 3
- Feature request: Add support for `separate.header = TRUE` used along with automatic header symbol formatting HOT 6
- Center and merge duplicated cells in `nice_table`
- change row names HOT 2
- Generation of a sample demographics table HOT 1
- test requires suggtested package HOT 5
- Package install issue HOT 4
- Comments on JOSS submission HOT 5
- Review for JOSS Submission HOT 2
- Nice_table: replacing rounding with scientific notation HOT 2
- How to make correlation tables with stars for significance? HOT 4
- Emmeans for nice_table? HOT 5
- generating tables for glmer models in rempsych HOT 13
- standardized slopes in nice_table() HOT 1
- Nice_table: Significance Asterisks for p value HOT 1
- `nice_lm()` doesn't work with lm models containing a single term
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rempsyc.