清除单个变量

rm(object) #变量名

清除所有变量

rm(list = ls())

注意,使用rm() 函数后虽然会删除变量,但只是从R的工作环境中删除了这些变量,并没有在你的电脑储存空间中完全删除这些变量,所以这些变量还是会占用电脑内存空间的

你可以理解为rm() 类似把文件丢到了回收站,但没有从回收站永久删除他们

如果想完全删除,需要再用一次 gc() 函数,并且gc() 函数会report目前的内存使用情况

在这里插入图片描述
R 的官方文档里写着,gc() 这个函数 A call of gc causes a garbage collection to take place. This will also take place automatically without user intervention, and the primary purpose of calling gc is for the report on memory usage. For an accurate report full = TRUE should be used.

It can be useful to call gc after a large object has been removed, as this may prompt R to return memory to the operating system.

R allocates space for vectors in multiples of 8 bytes: hence the report of “Vcells”, a relic of an earlier allocator (that used a vector heap).

所以可以用full = TRUE 这个参数来获得详细报告

清屏命令

Ctrl + L

只清屏, 并不会删除储存的变量名

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐