我的Description文件是:
Package: cancerProfile
Title: A collection of data sets of cancer
Version: 0.1
Authors@R: person("NavyCheng", email = "navycheng2020@gmail.com", role = c("aut", "cre"))
Description: This package contain some data sets of cancers, such as RNA-seq data, TF bind data and so on.
Depends: R (>= 3.4.0)
License: What license is it under?
Encoding: UTF-8
LazyData: true
我的项目是这样的:
cancerProfile.Rproj
NAMESPACE
LICENSE
DESCRIPTION
R/
data/
|-- prad.rna.count.rda
然后我安装我的软件包并加载它:
> library(pryr)
> library(devtools)
> install_github('hcyvan/cancerProfile')
> library(cancerProfile)
> mem_used()
82.2 MB
> invisible(prad.rna.count)
> mem_used()
356 MB
> ls()
character(0)
> prad.rna.count[1:3,1:3]
TCGA.2A.A8VL.01A TCGA.2A.A8VO.01A TCGA.2A.A8VT.01A
ENSG00000000003.13 2867 1667 3140
ENSG00000000005.5 6 0 0
ENSG00000000419.11 1354 888 1767
> rm(prad.rna.count)
Warning message:
In rm(prad.rna.count) : object 'prad.rna.count' not found
我的问题是为什么我不能'ls'和'rm'prad.rna.count,我该怎么办?
答案 0 :(得分:3)
在您的情况下,您无法ls()
或rm()
数据集,因为您从未将其放在全局环境中。考虑以下:
# devtools::install_github("hcyvan/cancerProfile")
library(cancerProfile)
library(pryr)
mem_used()
#> 31.8 MB
data(prad.rna.count)
mem_used()
#> 32.2 MB
ls()
#> [1] "prad.rna.count"
prad.rna.count[1:3,1:3]
#> TCGA.2A.A8VL.01A TCGA.2A.A8VO.01A TCGA.2A.A8VT.01A
#> ENSG00000000003.13 2867 1667 3140
#> ENSG00000000005.5 6 0 0
#> ENSG00000000419.11 1354 888 1767
mem_used()
#> 305 MB
rm(prad.rna.count)
ls()
#> character(0)
mem_used()
#> 32.5 MB
由reprex package(v0.2.1)于2019-01-15创建
由于我使用的是data()
而不是invisible()
,所以我实际上将数据放入了全局环境中,使我可以通过ls()
查看数据,并通过rm()
删除数据。我加载数据(data()
)的方式并没有增加内存使用量,因为它只是返回一个承诺,但是当我通过prad.rna.count[1:3,1:3]
评估承诺时,内存使用量猛增。幸运的是,由于我使用data()
而不是invisible()
来指向对象,因此当我使用rm(prad.rna.count)
时,R识别出不再有指向该对象的名称并释放了该对象。记忆。我会查看http://adv-r.had.co.nz/memory.html#gc和http://r-pkgs.had.co.nz/data.html#data-data以获得更多详细信息。