我分离了包装,现在无法分配值

时间:2018-10-09 01:55:10

标签: r package

糟糕。我未选中RStudio中的一堆软件包,但我认为未选中我不应该接触的关键软件包。现在,我什至无法做一些基本的事情,例如为变量赋值,例如a <- 1。我不断收到错误消息:

Error in object.size(obj) : could not find function "object.size"

这是我拆包时的代码。我只能假设这里有问题引起了问题:

> detach("package:bindrcpp", unload=TRUE)
Warning message:
‘bindrcpp’ namespace cannot be unloaded:
  namespace ‘bindrcpp’ is imported by ‘dplyr’ so cannot be unloaded 
> detach("package:dplyr", unload=TRUE)
Warning message:
‘dplyr’ namespace cannot be unloaded:
  namespace ‘dplyr’ is imported by ‘broom’, ‘recipes’ so cannot be unloaded 
> detach("package:readr", unload=TRUE)
> detach("package:vtreat", unload=TRUE)
> detach("package:broom", unload=TRUE)
Warning message:
‘broom’ namespace cannot be unloaded:
  namespace ‘broom’ is imported by ‘recipes’ so cannot be unloaded 
> detach("package:caret", unload=TRUE)
> detach("package:datasets", unload=TRUE)
> detach("package:DBI", unload=TRUE)
Error: package ‘DBI’ is required by ‘RJDBC’ so will not be detached
> detach("package:ggplot2", unload=TRUE)
> detach("package:graphics", unload=TRUE)
Warning message:
‘graphics’ namespace cannot be unloaded:
  namespace ‘graphics’ is imported by ‘rpart’, ‘geometry’, ‘pls’, ‘stats’, ‘kernlab’, ‘class’, ‘dimRed’, ‘MASS’, ‘nlme’, ‘survival’, ‘lava’, ‘scales’, ‘CVST’, ‘timeDate’, ‘psych’, ‘Matrix’, ‘colorspace’, ‘randomForest’, ‘lattice’, ‘robustbase’, ‘stats4’, ‘prodlim’, ‘splines’, ‘sfsmisc’, ‘ddalpha’, ‘magic’ so cannot be unloaded 
> detach("package:grDevices", unload=TRUE)
Warning message:
‘grDevices’ namespace cannot be unloaded:
  namespace ‘grDevices’ is imported by ‘rpart’, ‘graphics’, ‘grid’, ‘pls’, ‘stats’, ‘kernlab’, ‘dimRed’, ‘MASS’, ‘crayon’, ‘lava’, ‘psych’, ‘Matrix’, ‘colorspace’, ‘randomForest’, ‘lattice’, ‘robustbase’, ‘stats4’, ‘sfsmisc’, ‘ddalpha’ so cannot be unloaded 
> detach("package:glue", unload=TRUE)
Warning message:
‘glue’ namespace cannot be unloaded:
  namespace ‘glue’ is imported by ‘tidyselect’, ‘dplyr’, ‘tidyr’ so cannot be unloaded 
> detach("package:lattice", unload=TRUE)
Warning message:
‘lattice’ namespace cannot be unloaded:
  namespace ‘lattice’ is imported by ‘nlme’, ‘psych’, ‘Matrix’ so cannot be unloaded 
> detach("package:magrittr", unload=TRUE)
Warning message:
‘magrittr’ namespace cannot be unloaded:
  namespace ‘magrittr’ is imported by ‘dplyr’, ‘stringr’, ‘purrr’, ‘recipes’, ‘tidyr’ so cannot be unloaded 
> detach("package:methods", unload=TRUE)
Error: package ‘methods’ is required by ‘RJDBC’ so will not be detached
> detach("package:randomForest", unload=TRUE)
> detach("package:rJava", unload=TRUE)
Error: package ‘rJava’ is required by ‘RJDBC’ so will not be detached
> detach("package:reshape2", unload=TRUE)
Warning message:
‘reshape2’ namespace cannot be unloaded:
  namespace ‘reshape2’ is imported by ‘broom’ so cannot be unloaded 
> detach("package:RJDBC", unload=TRUE)
> detach("package:RODBC", unload=TRUE)
> detach("package:scales", unload=TRUE)
> detach("package:stats", unload=TRUE)
Warning message:
‘stats’ namespace cannot be unloaded:
  namespace ‘stats’ is imported by ‘DEoptimR’, ‘rpart’, ‘stringi’, ‘dplyr’, ‘lubridate’, ‘reshape2’, ‘ModelMetrics’, ‘pls’, ‘munsell’, ‘kernlab’, ‘data.table’, ‘class’, ‘foreign’, ‘dimRed’, ‘MASS’, ‘nlme’, ‘crayon’, ‘survival’, ‘mnormt’, ‘nnet’, ‘withr’, ‘lava’, ‘broom’, ‘CVST’, ‘timeDate’, ‘psych’, ‘plyr’, ‘Matrix’, ‘recipes’, ‘lattice’, ‘ipred’, ‘robustbase’, ‘stats4’, ‘prodlim’, ‘splines’, ‘sfsmisc’, ‘ddalpha’, ‘magic’ so cannot be unloaded 
> detach("package:teradataR", unload=TRUE)
> detach("package:utils", unload=TRUE)
Warning message:
‘utils’ namespace cannot be unloaded:
  namespace ‘utils’ is imported by ‘Rcpp’, ‘stringi’, ‘rJava’, ‘dplyr’, ‘lubridate’, ‘reshape2’, ‘abind’, ‘rstudioapi’, ‘grid’, ‘rlang’, ‘stats’, ‘data.table’, ‘foreign’, ‘dimRed’, ‘nlme’, ‘crayon’, ‘survival’, ‘nnet’, ‘tibble’, ‘lava’, ‘broom’, ‘pkgconfig’, ‘timeDate’, ‘psych’, ‘Matrix’, ‘recipes’, ‘lattice’, ‘ipred’, ‘robustbase’, ‘wrapr’, ‘foreach’, ‘sfsmisc’, ‘tidyr’, ‘ddalpha’, ‘magic’ so cannot be unloaded 

1 个答案:

答案 0 :(得分:1)

object.size is in the utils package:

> object.size
function (x) 
structure(.Call(C_objectSize, x), class = "object_size")
<bytecode: 0x561acd777668>
<environment: namespace:utils>

but detaching it shouldn't cause errors unless you try and use it:

> detach("package:utils")
> object.size(ls())
Error in object.size(ls()) : could not find function "object.size"

And doesn't cause assignment to fail for me...

> x = 1
> x
[1] 1

which makes me think RStudio (which I don't use) is at fault. I think it keeps a window of current R objects and their size, so it is probably relying on object.size being in the current search path, and when it isn't, most things you do will cause RStudio to complain.

As stated in comments, a restart of R (or a full RStudio restart) should clear it.