strengejacke / sjPlot

sjPlot - Data Visualization for Statistics in Social Science

Home Page:https://strengejacke.github.io/sjPlot

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Conflict with `psych::describe()` when loading the `Hmisc` package

isaactpetersen opened this issue · comments

Note that this is not an issue with sjPlot per se, but I was encouraged to open a new issue here with a reproducible example: #229

I'm trying to use the describe() function from the psych package. However, I receive an error when using it after having loaded the Hmisc package, even if specifying psych::describe():

> psych::describe(df)
Error in as.data.frame.default(utils::head(x, maxPrint)): cannot coerce class '"describe"' to a data.frame

I get the error when rendering an rmarkdown (.Rmd) file. I do not get the error when running the underlying R code. I still get the error even after unloading Hmisc. I've isolated the issue to when I am specifying df_print: paged in the YAML settings for html_document.

Here is a reproducible example with session info etc. (the error occurs in Section 9): https://isaactpetersen.github.io/reprex/

Here is the code (index.Rmd):

---
title: "Reproducible Example"
output:
  html_document:
    number_sections: true
    df_print: paged
---

```{r setup}
knitr::opts_chunk$set(echo = TRUE,
                      error = TRUE)
```

# Methods

```{r}
methods("describe")
```

# Load Libraries

```{r}
library("Hmisc", exclude = c("describe")) 
library("psych")
```

# Simulate Data

```{r}
set.seed(52242)

n <- 1000

ID <- rep(1:100, each = 10)
predictor <- rbeta(n, 1.5, 5) * 100
outcome <- predictor + rnorm(n, mean = 0, sd = 20) + 50

df <- data.frame(ID = ID,
                 predictor = predictor,
                 outcome = outcome)
```

# Session Info

`Hmisc` is loaded:

```{r}
sessionInfo()
```

# Methods

```{r}
methods("describe")
```

# Unload `Hmisc`

```{r}
unloadNamespace("Hmisc")
```

# Session Info

`Hmisc` is unloaded:

```{r}
sessionInfo()
```

# Methods

```{r}
methods("describe")
```

# Use `psych::describe()`

Throws error:

```{r}
psych::describe(df)
```

# Session Info

```{r}
sessionInfo()
```

I render the document using the following code:

rmarkdown::render("index.Rmd")