Skip to content
/ cpnr Public

Using R as an API to access tutorials for members of the conservation paleobiology network (cpn).

License

Notifications You must be signed in to change notification settings

Ischi94/cpnr

Repository files navigation

R-CMD-check Lifecycle: maturing GitHub R package version Website Status

cpnr: Interactive tutorials for conservation paleobiology

The Conservation Paleobiology Network (CPN) aims to transform conservation paleobiology into an applied science that informs conservation and restoration efforts. The project is envisioned as a grass-roots effort to develop strategies for communicating geohistorical data to stakeholder groups.

To facilitate interdisciplinary conservation work, the CPN now offers tutorials. These will cover various topics starting at an introductory level and aim to show students and scientists how to process geohistorical data. This document shows how to use the cpnr package and how to start a tutorial.

Please view our antiracism statement and call for action before proceeding.

The cpnrpackage builds on the amazing learnr package.

Requirements

All tutorials are deposited in a R package called cpnr, which is currently hosted on github. To access these tutorials, one needs to have R installed on their local device. You can download and install R here. Note that we recommend the usage of Rstudio, which you can download here. R and Rstudio is free and open source, and the R community is welcoming and very inclusive.

New to R

Here are some additional useful links if you are new to the R programming environment:
* Introduction to R (manual)
* R for data science (book)
* Data visualisations with R (book)

Why Github?

You might be familiar with installing packages from CRAN (the Comprehensive R Archive Network) in R. To install this package, you need to go a different route, as you will see below. Github allows us to provide real time access to our tutorials, as you will access the development version of the cpnr package.

How to start

The cpnr package provides interactive tutorials that can be accessed via R. For this, one needs to have the package installed and read into memory. To install the package from github, we can use the devtools package:

Install devtools

The devtools package is a tool that can be used to access packages from Github. It needs to be installed in order to access the cpnr package. You can check whether devtools is already installed by running the following command:

"devtools" %in% rownames(installed.packages())

If the previous command returned TRUE, you’re ready to go. If devtools is not installed, it will return FALSE and we need to install it from CRAN with the following command:

install.packages("devtools")

Install cpnr

With devtools installed to your local device, we are now ready to install the cpnr package from Github using the devtools::install_github() function:

devtools::install_github("Ischi94/cpnr")

To load the package into memory, use the library call.

library(cpnr)

Now you can access functions within the cpnr package.

Functions

See what is there

The training-series group of the CPN will add new tutorials to the package from time to time. To see all interactive tutorial currently available, you can use the show_tutorials function:

show_tutorials()
#> # A tibble: 1 x 2
#>   title  description         
#>   <chr>  <chr>               
#> 1 divdyn Fossil data analysis

There is currently one tutorial in the package. The show_tutorials call returns a dataframe with the title of the tutorial and a short description. To get further information on the tutorial, and to subsequently run it, the title of the tutorial is needed.

Further details

If the short description returned from show_tutorials is not sufficient for you to see what the tutorial contains, you can access a more detailed description via show_description. As mentioned above, we need the tutorial name as an argument for the function:

show_description(tutorial = "divdyn")
#> [1] "Fossil data analysis. This tutorial is aimed to introduce the `divDyn` package and its applications to data from the fossil record. In particular, you learn how to calculate taxonomic richness, extinction and origination rates from time‐binned fossil data using  state‐of‐the‐art methodology"

What you need

Each tutorial relies on various packages that might not be installed on your device. Running the tutorial without these packages will fail. It is therefore necessary to check which packages are needed to run the tutorial, and to install them if necessary.

show_dependencies(tutorial = "divdyn")
#> [1] "divDyn"    "knitr"     "learnr"    "rmarkdown" "shiny"

To load all these dependencies needed to run a tutorial, and to install the missing ones, you can run load_depencies:

# get dependencies
packages <- show_dependencies(tutorial = "divdyn")

# load or install them
load_dependencies(packages = packages)

Access the tutorial

Now you should know the name of the tutorial you want to run and what it does based on the description. Further, you have loaded and installed all dependencies needed to run the tutorial. Now you are ready to run it. The start_tutorial function will initiate the interactive tutorial and open it in a browser:

start_tutorial(tutorial = "divdyn")

End the tutorial

When you are done with a tutorial, close the tab in your browser and return to RStudio. Here you can just press the Esc button to end the tutorial. You could also click on the red Stop button in the upper right corner of the console.