ScienceToolbox / code_citations

Ruby gem for finding citations of open scientific code
MIT License
10 stars 1 forks source link

How to get citation for a package on CRAN in Ruby #1

Closed jure closed 10 years ago

jure commented 10 years ago

Opening an issue to use as notes.

It's fairly easy to use R from Ruby using the rinruby gem, but to get a citation using R's citation('packagename') function, you would need to first install the package and then run the citation command. Ideally, we'd like to do that without massive downloads that I'm sure some packages are.

So how do you do it without installing a package and in Ruby?

Some relevant info is here: http://stackoverflow.com/questions/9324869/how-do-i-determine-the-author-of-an-r-package

jure commented 10 years ago

Just as a proof of concept:

[1] pry(main)> R.eval "y <- citation(\"vegan\")"
.RINRUBY.PARSE.STRING <- rinruby_get_value()
rinruby_parseable(.RINRUBY.PARSE.STRING)
rm(.RINRUBY.PARSE.STRING)
      rinruby_pull(try(x))
.RINRUBY.PARSE.STRING <- rinruby_get_value()
rinruby_parseable(.RINRUBY.PARSE.STRING)
rm(.RINRUBY.PARSE.STRING)
y <- citation("vegan")
print('RINRUBY.EVAL.FLAG')
=> true
[2] pry(main)> copy_of_y = R.pull "as.character(y)"
=> "list(title = \"vegan: Community Ecology Package\", author = list(list(given = \"Jari\", family = \"Oksanen\", role = NULL, email = NULL, comment = NULL), list(given = c(\"F.\", \"Guillaume\"), family = \"Blanchet\", role = NULL, email = NULL, comment = NULL), list(given = \"Roeland\", family = \"Kindt\", role = NULL, email = NULL, comment = NULL), list(given = \"Pierre\", family = \"Legendre\", role = NULL, email = NULL, comment = NULL), list(given = c(\"Peter\", \"R.\"), family = \"Minchin\", role = NULL, email = NULL, comment = NULL), \n    list(given = c(\"R.\", \"B.\"), family = \"O'Hara\", role = NULL, email = NULL, comment = NULL), list(given = c(\"Gavin\", \"L.\"), family = \"Simpson\", role = NULL, email = NULL, comment = NULL), list(given = \"Peter\", family = \"Solymos\", role = NULL, email = NULL, comment = NULL), list(given = c(\"M.\", \"Henry\", \"H.\"), family = \"Stevens\", role = NULL, email = NULL, comment = NULL), list(given = \"Helene\", family = \"Wagner\", role = NULL, email = NULL, comment = NULL)), year = \"2013\", note = \"R package version 2.0-10\", \n    url = \"http://CRAN.R-project.org/package=vegan\")"
jure commented 10 years ago

This became irrelevant: even though the R's citation() function is quite complex (https://svn.r-project.org/R/trunk/src/library/utils/R/citation.R), it is actually not necessary to replicate its behavior for what we want to do. Instead the necessary data (authors, project name, etc.) can be retrieved from a project's web page on CRAN (which is what we do right now), or alternatively its DESCRIPTION file.