Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if a function name is used in existing CRAN packages

Tags:

r

cran

I am creating an R package that I plan to submit to CRAN. How can I check if any of my function names conflict with function names in packages already on CRAN? Before my package goes public, it's still easy to change the names of functions, and I'd like to be a good citizen and avoid conflicts where possible.

For instance, the packages MASS and dplyr both have functions called "select". I'd like to avoid that sort of collision.

like image 395
Sam Firke Avatar asked Aug 22 '16 15:08

Sam Firke


1 Answers

There are a lot of packages (9008 at the moment, Aug 2016), so it is almost certainly better to only look at a subset you want to avoid clashes with. Also, to re-emphasise some of the good advice in the comments (just for the record in case comments get deleted, or hidden):

  1. sharing function names with other packages is not really a big problem, and not worth avoiding beyond, perhaps avoiding clashes with common packages that are most likely to be loaded at the same time (thanks @Nicola and @Joran)
  2. Unnecessarily avoiding re-usue of names "leads to bad function names because the good ones are taken" (@Konrad Rudolph)

But, if you really want to check all the packages, perhaps to at least know which packages use the same names as yours, you can get a vector of the package names by

crans <- available.packages()[, "Package"]
#           A3        abbyyR           abc   ABCanalysis      abc.data      abcdeFBA 
#         "A3"      "abbyyR"         "abc" "ABCanalysis"    "abc.data"    "abcdeFBA"
length(crans)
# [1] 9008

You can then install them in bulk using

N = 4 # only using the 1st 4 packages here - 
      # doing it for the whole lot will take a lot of time and disk space!!!
install.packages(crans[1:N])

Then you can get a list of the function names in these packages with

existing_functions = sapply(1:N, function(i)  ls(getNamespace(crans[i])))
like image 74
dww Avatar answered Sep 23 '22 06:09

dww