initFields(scales = scales) 错误:找不到函数 "initRefFields"

Error in initFields(scales = scales) : could not find function "initRefFields"

我的代码中有一个 ggplot2 绘图函数。 当文件作为 R 代码获取时,该函数工作正常,但是当我将此函数包含在 R 包中时(当然我在描述和包的 NAMESPACE 文件中包含 ggplot2 和比例)我得到以下信息错误:

Error in initFields(scales = scales) : 
  could not find function "initRefFields"

ggplot2对象中的比例尺分别调用如下:

+ facet_wrap(~PV_Type, ncol = 1, scales = "free") +

我运行 从源安装了最新的 R (3.2.0) 和最新的 ggplot2 (1.0.1)。

一个可能的 solution/explanation 将不胜感激!

编辑:sessionInfo() 的输出如下:

R version 3.2.0 (2015-04-16)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.3 (Yosemite)

locale:
[1] C/UTF-8/C/C/C/C

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

other attached packages:
[1] argparse_1.0.1 proto_0.3-10   greater_1.0

loaded via a namespace (and not attached):
 [1] Rcpp_0.11.6        DEoptimR_1.0-2     RColorBrewer_1.1-2 plyr_1.8.2
 [5] methods_3.2.0      class_7.3-12       prabclus_2.2-6     tools_3.2.0
 [9] digest_0.6.8       mclust_5.0.1       gtable_0.1.2       lattice_0.20-31
[13] mvtnorm_1.0-2      findpython_1.0.1   gridExtra_0.9.1    trimcluster_0.1-2
[17] stringr_1.0.0      cluster_2.0.1      RGraphics_2.0-12   fpc_2.1-9
[21] stats4_3.2.0       diptest_0.75-6     grid_3.2.0         nnet_7.3-9 
[25] getopt_1.20.0      robustbase_0.92-3  flexmix_2.3-13     pander_0.5.1
[29] ggplot2_1.0.1      reshape2_1.4.1     kernlab_0.9-20     magrittr_1.5
[33] scales_0.2.4       modeltools_0.2-21  MASS_7.3-40        colorspace_1.2-6
[37] stringi_0.4-1      munsell_0.4.2      rjson_0.2.15

.libPaths() 在我的安装中也很常见:

>.libPaths()
[1] "/Library/Frameworks/R.framework/Versions/3.2/Resources/library"

也许我还应该补充一点,我从命令行 R 脚本调用需要 scales 包的函数。

(这不是 ggplot2 Error in initFields 的副本,因为我尝试了他们所有的建议(当然除了恢复到 R 2.14)并且 none 有效)。

我想我找到了 solution/workaround。

正如我从 sessionInfo() 中注意到的那样,methods 包未附加,而是加载到命名空间中。因此,在附加 methods (以及后续函数所需的 grid )之后,我的脚本通过加载包中的函数可以正常工作。

我的工作 sessionInfo() 现在看起来像这样:

R version 3.2.0 (2015-04-16)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.3 (Yosemite)

locale:
[1] C/UTF-8/C/C/C/C

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

other attached packages:
[1] argparse_1.0.1 proto_0.3-10   greater_1.0

loaded via a namespace (and not attached):
 [1] Rcpp_0.11.6        DEoptimR_1.0-2     RColorBrewer_1.1-2 plyr_1.8.2
 [5] class_7.3-12       prabclus_2.2-6     tools_3.2.0        digest_0.6.8
 [9] mclust_5.0.1       gtable_0.1.2       lattice_0.20-31    mvtnorm_1.0-2
[13] findpython_1.0.1   gridExtra_0.9.1    trimcluster_0.1-2  stringr_1.0.0
[17] cluster_2.0.1      RGraphics_2.0-12   fpc_2.1-9          stats4_3.2.0
[21] diptest_0.75-6     nnet_7.3-9         getopt_1.20.0      robustbase_0.92-3
[25] flexmix_2.3-13     pander_0.5.1       ggplot2_1.0.1      reshape2_1.4.1
[29] kernlab_0.9-20     magrittr_1.5       scales_0.2.4       modeltools_0.2-21
[33] MASS_7.3-40        colorspace_1.2-6   stringi_0.4-1      munsell_0.4.2
[37] rjson_0.2.15

非常感谢您的贡献,但是我希望首先解释为什么在加载函数时需要显式附加这两个包(methodsgrid)一个包,当函数由 source().

提供时不需要