The R package "cranium"
is part of the Craniography project for exploring R packages in CRAN (Comprehensive R Archive Network).
It is developed and maintained by Gaston Sanchez, and kindly shared to the R community.
An integral part of the craniography project is the R package
"cranium"
freely available on github. To install the package,
open your R console and run the following commands:
# install "devtools" (if you don't have it yet)
install.packages("devtools")
# load devtools
library(devtools)
# install "cranium"
install_github('cranium', username = 'gastonstat')
# load cranium
librayr(cranium)
"cranium"
allows you to do three major tasks:
D3.js
To parse the description of an R package's current version, pass the name of the package you are interested in to the scrape_current_pkg()
function. The output is a list with all the attributes of the package's description:
# R package 'plspm'
package_name = "plspm"
# List of attributes from the current description of 'plspm'
current_plspm = scrape_current_pkg(package_name)
To parse previous versions (i.e. archived versions) of an R package, pass the name of the package you are interested in to the
scrape_previous_pkg()
function. The output is a data frame with the information of previous versions:
# R package 'plspm'
package_name = "plspm"
# Data Frame with the previous versions of 'plspm'
prev_table = scrape_previous_pkg(package_name)
Most of the times it's a good idea to save a local copy of the HTML CRAN descriptions of the explored package. You can download the HTML file with the current description of an R package like this:
# R package 'plspm'
package_name = "plspm"
# destiny file
html_current = "plspm_current.html"
# download local html copy (in your working directory)
download_current_pkg(package_name, html_current)
Most of the times it's a good idea to save a local copy of the HTML CRAN descriptions of the explored package. You can download the HTML file with the archived (previous) versions of an R package like this:
# R package 'plspm'
package_name = "plspm"
# destiny file
html_previous = "plspm_previous.html"
# download local html copy (in your working directory)
download_previous_pkg(package_name, html_previous)
To help you visualize the dependencies of an R package using the
D3.js JavaScript library, "cranium"
prodives the function build_json_tree()
to get a json file with the right data structure required by tree layouts
(eg Radial Reingold–Tilford Tree,
Dendrogram)
# List of attributes from the current description of 'plspm'
current_plspm = scrape_current_pkg(package_name)
# select dependencies of 'plspm'
plspm_deps = current_plspm[c("depends", "imports", "suggests",
"revdepends", "revimports", "revsuggests")]
build_json_tree(plspm_deps, file = "toy_json_tree.json")
Gaston Sanchez
(gaston.stat at gmail.com
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.