gpt4 book ai didi

r - 下一个行为如何发生(Hmisc 何时/何地导出 `[` )以及在哪里解决它?

转载 作者:行者123 更新时间:2023-12-04 16:56:53 25 4
gpt4 key购买 nike

该行为涉及 3 个包:Hmisc , psychmediation .加载包后 psychmediation函数[.describe来自 Hmisc ,但是没有冲突,也没有加载这个包。为什么以及如何发生这种情况? (实际上我最后可以看到问题出在 loaded via a namespace (and not attached) 行)
让我们首先加载 psych并使用其功能 describe .然后我们对用 [ 生成的对象的一些列进行子集化:

data(sat.act)
ooi <- describe(sat.act)
str(ooi)
Classes ‘psych’, ‘describe’ and 'data.frame': 6 obs. of 13 variables:
$ vars : int 1 2 3 4 5 6
$ n : num 700 700 700 700 700 687
$ mean : num 1.65 3.16 25.59 28.55 612.23 ...
$ sd : num 0.478 1.425 9.499 4.824 112.903 ...
$ median : num 2 3 22 29 620 620
$ trimmed : num 1.68 3.31 23.86 28.84 619.45 ...
$ mad : num 0 1.48 5.93 4.45 118.61 ...
$ min : num 1 0 13 3 200 200
$ max : num 2 5 65 36 800 800
$ range : num 1 5 52 33 600 600
$ skew : num -0.615 -0.681 1.643 -0.656 -0.644 ...
$ kurtosis: num -1.6247 -0.0749 2.4243 0.535 0.3252 ...
$ se : num 0.0181 0.0539 0.359 0.1823 4.2673 ...
str(ooi[,c(1,2)])
Classes ‘psych’, ‘describe’ and 'data.frame': 6 obs. of 2 variables:
$ vars: int 1 2 3 4 5 6
$ n : num 700 700 700 700 700 687
直到这里一切顺利。现在让我们加载库 mediation :
library(mediation)
Loading required package: MASS
Loading required package: Matrix
Loading required package: mvtnorm
Loading required package: sandwich
mediation: Causal Mediation Analysis
Version: 4.5.0


Attaching package: ‘mediation’

The following object is masked from ‘package:psych’:

mediate

search()
[1] ".GlobalEnv" "package:mediation" "package:sandwich" "package:mvtnorm" "package:Matrix"
[6] "package:MASS" "package:psych" "tools:rstudio" "package:stats" "package:graphics"
[11] "package:grDevices" "package:utils" "package:datasets" "package:methods" "Autoloads"
[16] "package:base"
图书馆 Hmisc尚未加载,但上述相同命令的输出发生了变化:
str(ooi[,c(1,2)])
List of 13
$ vars : int [1:6] 1 2 3 4 5 6
$ n : num [1:6] 700 700 700 700 700 687
$ mean : num [1:6] 1.65 3.16 25.59 28.55 612.23 ...
$ sd : num [1:6] 0.478 1.425 9.499 4.824 112.903 ...
$ median : num [1:6] 2 3 22 29 620 620
$ trimmed : num [1:6] 1.68 3.31 23.86 28.84 619.45 ...
$ mad : num [1:6] 0 1.48 5.93 4.45 118.61 ...
$ min : num [1:6] 1 0 13 3 200 200
$ max : num [1:6] 2 5 65 36 800 800
$ range : num [1:6] 1 5 52 33 600 600
$ skew : num [1:6] -0.615 -0.681 1.643 -0.656 -0.644 ...
$ kurtosis: num [1:6] -1.6247 -0.0749 2.4243 0.535 0.3252 ...
$ se : num [1:6] 0.0181 0.0539 0.359 0.1823 4.2673 ...
- attr(*, "row.names")= chr [1:6] "gender" "education" "age" "ACT" ...
- attr(*, "dimensions")= int 13
- attr(*, "class")= chr "describe"
接下来我尝试调试,我发现它正在使用 [.describe来自 Hmisc 的命名空间:
enter image description here
我试图理解,但我不能:
getNamespaceImports("mediation")$Hmisc
wtd.var
"wtd.var"
is.loaded("[","Hmisc")
[1] FALSE
is.loaded("[.describe","Hmisc")
[1] FALSE
grep("\\[",getNamespaceExports("Hmisc"), value=TRUE)
[1] "[<-.discrete"


sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.7 LTS

Matrix products: default
BLAS: /usr/lib/atlas-base/atlas/libblas.so.3.0
LAPACK: /usr/lib/atlas-base/atlas/liblapack.so.3.0

locale:
[1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8 LC_COLLATE=C.UTF-8
[5] LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8 LC_PAPER=C.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C

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

other attached packages:
[1] mediation_4.5.0 sandwich_3.0-0 mvtnorm_1.1-1 Matrix_1.2-18 MASS_7.3-53 psych_2.0.12

loaded via a namespace (and not attached):
[1] nlme_3.1-149 lubridate_1.7.9.2 RColorBrewer_1.1-2 numDeriv_2016.8-1.1
[5] backports_1.2.0 tools_4.0.3 R6_2.5.0 rpart_4.1-15
[9] afex_0.28-0 Hmisc_4.4-2 colorspace_2.0-0 nnet_7.3-14
[13] withr_2.3.0 tidyselect_1.1.0 gridExtra_2.3 mnormt_2.0.2
[17] emmeans_1.5.2-1 curl_4.3 compiler_4.0.3 cli_2.2.0
[21] htmlTable_2.1.0 scales_1.1.1 checkmate_2.0.0 digest_0.6.27
[25] stringr_1.4.0 foreign_0.8-80 minqa_1.2.4 rio_0.5.16
[29] htmltools_0.5.0 base64enc_0.1-3 jpeg_0.1-8.1 pkgconfig_2.0.3
[33] lme4_1.1-26 htmlwidgets_1.5.2 rlang_0.4.9 readxl_1.3.1
[37] rstudioapi_0.13 generics_0.1.0 zoo_1.8-8 dplyr_1.0.2
[41] ModelMetrics_1.2.2.2 zip_2.1.1 car_3.0-10 magrittr_2.0.1
[45] Formula_1.2-4 Rcpp_1.0.5 munsell_0.5.0 fansi_0.4.1
[49] abind_1.4-5 lifecycle_0.2.0 stringi_1.5.3 multcomp_1.4-15
[53] pROC_1.16.2 carData_3.0-4 plyr_1.8.6 recipes_0.1.15
[57] grid_4.0.3 parallel_4.0.3 forcats_0.5.0 crayon_1.3.4
[61] lattice_0.20-41 haven_2.3.1 splines_4.0.3 hms_0.5.3
[65] tmvnsim_1.0-2 knitr_1.30 pillar_1.4.7 boot_1.3-25
[69] estimability_1.3 lpSolve_5.6.15 reshape2_1.4.4 codetools_0.2-16
[73] stats4_4.0.3 glue_1.4.2 latticeExtra_0.6-29 data.table_1.13.2
[77] vctrs_0.3.5 png_0.1-7 nloptr_1.2.2.2 foreach_1.5.1
[81] cellranger_1.1.0 gtable_0.3.0 purrr_0.3.4 assertthat_0.2.1
[85] ggplot2_3.3.2 xfun_0.19 gower_0.2.2 openxlsx_4.2.3
[89] prodlim_2019.11.13 xtable_1.8-4 class_7.3-17 survival_3.2-7
[93] timeDate_3043.102 tibble_3.0.4 lmerTest_3.1-3 iterators_1.0.13
[97] cluster_2.1.0 lava_1.6.8.1 statmod_1.4.35 TH.data_1.0-10
[101] ellipsis_0.3.1 caret_6.0-86 ipred_0.9-9
谢谢!

最佳答案

这个问题在 R-devel 列表中讨论:https://stat.ethz.ch/pipermail/r-devel/2021-June/080859.html
由 Simon Urbanek 和 Gabriel Becker 解释的答案。
这还不是一个确定的答案,因为它没有讨论完全相同的问题(它不是由第三个包导入的函数,而是一个使包被加载的使用函数)并且它没有详细解释它是如何发生的。

关于r - 下一个行为如何发生(Hmisc 何时/何地导出 `[` )以及在哪里解决它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65923769/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com