R语言 出现的问题及解决

问题一:

object(s) are masked from package - what does it mean?

 


Sometime when I attach a dataset, R gives me the following message/warning:"The following object(s) are masked from package:datasets: column_name". Does anyone know what it means? Since it seems that the dataset was attached and I could manipulate the data from the dataset without problems, I am wondering what was R trying to tell me. 
有时,当我将一个数据集,R给我 留言/警告:“下面的对象(S)被屏蔽 包:数据集: 列名“。有谁知道这是什么意思呢?因为它似乎 连接数据集,我可以操纵的数据集的数据 没有问题的,我想知道什么是R试图告诉我。 


This has to do with R's searchpath. 

When you attach() a dataset, it loads the dataset into R's current searchpath. The same occurs with packages when you use library(). This can be seen with: 

这里需要做R的搜索路径。当你将使用attach()连接数据集,数据集加载到R的 搜索路径。发生同样的包时,你使用的library()。 可以看出:

 
search() 

[1] ".GlobalEnv" "package:Design" "package:survival" 
[4] "package:splines" "package:Hmisc" "package:chron" 
[7] "package:xtable" "package:gplots" "package:gtools" 
[10] "package:gmodels" "package:gdata" "package:methods" 
[13] "package:stats" "package:graphics" "package:grDevices" 
[16] "package:utils" "package:datasets" "Autoloads" 
[19] "package:base" 
 
or with a bit more detail: 

searchpaths() 
[1] ".GlobalEnv" 
[2] "/usr/local/lib/R/library/Design" 
[3] "/usr/local/lib/R/library/survival" 
[4] "/usr/local/lib/R/library/splines" 
[5] "/usr/local/lib/R/library/Hmisc" 
[6] "/usr/local/lib/R/library/chron" 
[7] "/usr/local/lib/R/library/xtable" 
[8] "/usr/local/lib/R/library/gplots" 
[9] "/usr/local/lib/R/library/gtools" 
[10] "/usr/local/lib/R/library/gmodels" 
[11] "/usr/local/lib/R/library/gdata" 
[12] "/usr/local/lib/R/library/methods" 
[13] "/usr/local/lib/R/library/stats" 
[14] "/usr/local/lib/R/library/graphics" 
[15] "/usr/local/lib/R/library/grDevices" 

[16] "/usr/local/lib/R/library/utils" 
[17] "/usr/local/lib/R/library/datasets" 
[18] "Autoloads" 
[19] "/usr/local/lib/R/library/base" 

You can see that the 'datasets' package is number 17 in the searchpath. 
 

For example, if I now attach() the iris dataset (a widely used example 
dataset in R): 
 
attach(iris) 
search() 
[1] ".GlobalEnv" "iris" "package:Design" 
[4] "package:survival" "package:splines" "package:Hmisc" 
[7] "package:chron" "package:xtable" "package:gplots" 
[10] "package:gtools" "package:gmodels" "package:gdata" 
[13] "package:methods" "package:stats" "package:graphics" 
[16] "package:grDevices" "package:utils" "package:datasets" 
[19] "Autoloads" "package:base" 

 
You can see that 'iris' is now number 2 in the searchpath. This means that I can now access columns in the iris dataset without needing to use the typical DataframeName$ColumnName syntax: 

Species 
[1] setosa setosa setosa setosa setosa setosa 
[7] setosa setosa setosa setosa setosa setosa 
... 
 
However: 

 detach(iris) 
Species 
Error: object "Species" not found 
iris$Species 
[1] setosa setosa setosa setosa setosa setosa 
[7] setosa setosa setosa setosa setosa setosa 
... 


In your case, the warning is telling you that you have attached a data frame that presumably contains a column, whose name is 'column_name'. If you use: 

 column_name 

in your R session, the object with that name in your data frame will be seen before another object with the same name that is lower in the searchpath, since your object is higher in the searchpath. Thus, your object is 'masking' the other. 

I did not see another object called column_name in my version of the datasets package, so perhaps you have done some manipulation on those objects during your R session. 

 As a general comment, as has been discussed previously in other threads, this is a potentially significant danger in the habit of using attach() and should generally be avoided. 

 暂时解决办法:

在RStudio里面重启。

 

问题二:

错误于plot.new() : 图版边太大

 

暂时解决办法:

在RStudio里面把画图窗口调大。


问题三:

使用弹出对话框设定工作路径
解决方法:
setwd(choose.dir("Choose a suitable folder")) 

 

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值