SachaEpskamp / qgraph

Developmental version of qgraph
GNU General Public License v2.0
68 stars 21 forks source link

qgraph introduces a conflict with psych describe #86

Open revelle opened 6 months ago

revelle commented 6 months ago

I am not sure what is happening, but there seems to be a conflict introduced into showing just part of a data.frame when using qgraph

library(psych)

library(psychTools)
test <- describe(sat.act)      
> test[,2:4]#this works
            n   mean     sd
gender    700   1.65   0.48
education 700   3.16   1.43
age       700  25.59   9.50
ACT       700  28.55   4.82
SATV      700 612.23 112.90
SATQ      687 610.22 115.64
> library(qgraph)  
library(qgraph)
> test[,2:4]      #but this does not

 NA  Variables      13  Observations
-----------------------------------------------------------------------------------------------------------------------------------------------------
Error in x$descript : $ operator is invalid for atomic vectors
class(test)
[1] "psych"      "describe"   "data.frame"
 test
          vars   n   mean     sd median trimmed    mad min max range  skew kurtosis   se
gender       1 700   1.65   0.48      2    1.68   0.00   1   2     1 -0.61    -1.62 0.02
education    2 700   3.16   1.43      3    3.31   1.48   0   5     5 -0.68    -0.07 0.05
age          3 700  25.59   9.50     22   23.86   5.93  13  65    52  1.64     2.42 0.36
ACT          4 700  28.55   4.82     29   28.84   4.45   3  36    33 -0.66     0.53 0.18
SATV         5 700 612.23 112.90    620  619.45 118.61 200 800   600 -0.64     0.33 4.27
SATQ         6 687 610.22 115.64    620  617.25 118.61 200 800   600 -0.59    -0.02 4.41

but

test[,2:4]

 NA  Variables      13  Observations
revelle commented 6 months ago

It seems be due to something in the way Hmisc handles data frames.

test <- describe(sat.act)       
test <- describe(sat.act)
> class(test)
[1] "psych"      "describe"   "data.frame"
> class(test[,2:4])
[1] "describe"
> test  #this works
          vars   n   mean     sd median trimmed    mad min max range  skew kurtosis   se
gender       1 700   1.65   0.48      2    1.68   0.00   1   2     1 -0.61    -1.62 0.02
education    2 700   3.16   1.43      3    3.31   1.48   0   5     5 -0.68    -0.07 0.05
age          3 700  25.59   9.50     22   23.86   5.93  13  65    52  1.64     2.42 0.36
ACT          4 700  28.55   4.82     29   28.84   4.45   3  36    33 -0.66     0.53 0.18
SATV         5 700 612.23 112.90    620  619.45 118.61 200 800   600 -0.64     0.33 4.27
SATQ         6 687 610.22 115.64    620  617.25 118.61 200 800   600 -0.59    -0.02 4.41
> test[,2:4] #this does not

 NA  Variables      13  Observations

A traceback shows that the print method is dispatching print.describe (but not psych.print.describe) traceback() 3: print.describe.single(z, ...) 2: print.describe(x) 1: (function (x, ...) UseMethod("print"))(x)

SachaEpskamp commented 6 months ago

Thanks! I am looking into this and indeed seems to be due to Hmisc, but I don't really get yet why it happens as qgraphd doesn't export any function from Hmisc...

revelle commented 6 months ago

Sacha,

I think it because “tidy” is attaching it somehow.

I just figured out a work around, I will change the class of describe from "psych" "describe" “data.frame” to "psych" "P_describe" “data.frame” and adjust my print statement.

This will be an improvement in that I had problems with Hmisc::describe before.

When did you move to Singapore?

Bill

On Feb 25, 2024, at 20:16, Sacha Epskamp @.***> wrote:

Thanks! I am looking into this and indeed seems to be due to Hmisc, but I don't really get yet why it happens as qgraphd doesn't export any function from Hmisc... — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you modified the open/close state.Message ID: @.***>

William Revelle personality-project.org/revelle.html Professor personality-project.org Department of Psychology www.wcas.northwestern.edu/psych/ Northwestern University www.northwestern.edu/ Use R for psychology personality-project.org/r It 90 seconds to midnight www.thebulletin.org

SachaEpskamp commented 6 months ago

Hi Bill,

Hm, qgraph doesn't import tidyr/dplyr. It imports ggplot2 but it seemed to me removing that from NAMESPACE didn't change the problem. I'll keep this issue open to look into it later as well, but if you have a workaround now that is great!

I moved to Singapore in 2022!

Best,. Sacha

emstruong commented 6 months ago

Hi Sacha and Bill,

For what it's worth, Hadley says that it has to do psych, but perhaps that's just an impression.

As I said later in that thread, to me the immediate concern is how this happened between qgraph and psych specifically. But then the overall concern is what pairs of R packages may be interacting with each other without any obvious messages popping up...

I'll close the other issue.

Michael