如何确定我的R脚本中没有使用哪些软件包? [英] How can I tell which packages I am not using in my R script?

查看:73
本文介绍了如何确定我的R脚本中没有使用哪些软件包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着我的代码从一个版本到另一个版本的发展,我知道有些软件包为我的任务找到了更好/更合适的软件包,或者其目的仅限于我自己的一段代码.现在已经淘汰了.

As my code evolves from version to version, I'm aware that there are some packages for which I've found better/more appropriate packages for the task at hand or whose purpose was limited to a section of code which I've now phased out.

有没有一种简单的方法来判断给定脚本中实际使用了哪些已加载的软件包?我的标题开始变得混乱.

Is there any easy way to tell which of the loaded packages are actually used in a given script? My header is beginning to get cluttered.

推荐答案

更新2020-04-13

我现在已经更新了引用的函数,以使用抽象语法树(AST)而不是像以前那样使用正则表达式.这是解决问题的一种更可靠的方法(仍然没有完全解决).从funchir的0.2.0版本开始,现在位于CRAN上.

Update 2020-04-13

I've now updated the referenced function to use the abstract syntax tree (AST) instead of using regular expressions as before. This is a much more robust way of approaching the problem (it's still not completely ironclad). This is available from version 0.2.0 of funchir, now on CRAN.

我刚刚写了一个快速脏函数来处理这个问题,我称之为stale_package_check,然后将其添加到我的包中(

I've just got around to writing a quick-and-dirty function to handle this which I call stale_package_check, and I've added it to my package (funchir).

例如,如果我们将以下脚本另存为test.R:

e.g., if we save the following script as test.R:

library(data.table)
library(iotools)
DT = data.table(a = 1:3)

然后(从带有该脚本的目录中)运行funchir::stale_package_check('test.R'),我们将获得:

Then (from the directory with that script) run funchir::stale_package_check('test.R'), we'll get:

与包data.table匹配的功能:data.table

Functions matched from package data.table: data.table

**没有从iotools匹配的导出函数**

**No exported functions matched from iotools**

这篇关于如何确定我的R脚本中没有使用哪些软件包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆