Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine name of R package my code is in?

Tags:

package

r

I'm working on an R package and (in the package's code) need to determine the version number when a certain function is called.

packageVersion("mypackage") works, but I'd rather not hard code the name of the package. How can I ask "what's the name of the package I'm in"? (Or directly get the version number of the package I'm in.)

like image 667
DavidC Avatar asked Jan 27 '16 13:01

DavidC


People also ask

How do I view the source code of an R package?

Compiled code built into the R interpreter. If you want to view the code built-in to the R interpreter, you will need to download/unpack the R sources; or you can view the sources online via the R Subversion repository or Winston Chang's github mirror.

How do I name an R package?

But R packages have fairly strict naming rules: There are three formal requirements: the name can only consist of letters, numbers and periods, i.e., .; it must start with a letter; and it cannot end with a period.

What is the main repository for R packages?

You can find thousands of R packages online. The two biggest sources of packages are CRAN (Comprehensive R Archive Network) and Bioconductor, but some packages are available elsewhere.


2 Answers

This mailing list thread describes packageName().

(As Martin pointed out in comments.)

like image 96
DavidC Avatar answered Oct 17 '22 02:10

DavidC


I have not handled working with packages. But I am assuming you can use something like

packageVersion(getPackageName())

While you can supply parameters to getPackageName to search for the package name you are looking for, I think just supplying it without any parameters will get the current environment, (and in your case) the current package.

Source: The R Reference Index, available at https://cran.r-project.org/manuals.html

like image 3
Kenric D'souza Avatar answered Oct 17 '22 03:10

Kenric D'souza