labzenr is a R package that adds more zen to your student experience of working on MDS labs. It lets you manage common tasks such as counting total marks in an assignment, and performs common checks for mechanics in your iPython notebooks and R markdown assignments.

In this vignette, we will show you how to give labzenr a spin!

Setup

After installing labzenr, run usethis::git_sitrep() to obtain a situation report of your local Git credentials status.

If the printout indicates that you do not a token setup, you will need to follow the instructions to set up your credentials first.

For this demo, we’ll pretend as if we are in a directory on our computer containing just one lab file (ending in either .Rmd or .ipynb):

#> [1] "~/mds/block1/dsci999/lab2"

We can check what files are in the current directory:

#> [1] "~/mds/block1/dsci999/lab2/lab2.Rmd"

Checking Mechanics

Have you ever forgotten to include a Github link, to push your main branch to Github Enterprise, or to commit at least three times?

check_mechanics() is your friend. Let it perform these checks so that you never lose mechanics marks again!

#> ℹ Using lab2.Rmd
#> ✓ You included the repo link https://github.ubc.ca/MDS-2020-21/DSCI_998_lab1_johnsmith
#> ✓ Remote has the latest commit
#> Trying to authenticate 'git' using ssh-agent...
#> ✓ No unrecognized Git signatures found. To add signatures manually, use `labzenr::signature_add()`.
#> ℹ To see the list of currently registered signatures, run `labzenr::signature_ls()`.
#> ✓ Repo has at least 3 commits with users listed in `labzenr::signature_student()`

In the above printout, we can see that the function is detecting a lab2.Rmd file (based on the working directory). Several checks passed:

  • It found that we included a Github link to our MDS-2020-21/DSCI_998_lab1_johnsmith repo
  • It used an SSH connection to check that our main branch was pushed (you may need to set up your creditials first).
  • It found that we had at least three student commits in the repo.

If it is your first time using labzenr, the package will not know which Github authors in the Git log are you, and which are an instructor. If so, it will set up a persistent cache and ask you:

'Dr. Strange <strange@stat.ubc.ca>' is a 

1: Student
2: Instructor
3: I don't know! (escape)

In the above example, we would want to enter “2” in the console in order to add our professor Dr. Strange into our cache of known instructors. This will allow check_mechanics() to count the number of student commits, while ignoring the instructor commits.

Anytime you switch labs and a new git author is found in your log, labzen will ask you about it. To view your cache of known Git users, run labzenr::signature_ls():

> signature_ls()
✓ No unrecognized Git signatures found. To add signatures manually, use `labzenr::signature_add()`.
ℹ To see the list of currently registered signatures, run `labzenr::signature_ls()`.
# A tibble: 8 x 3
  signature                        is_user is_regexp
  <chr>                            <lgl>   <lgl>    
1 John Smith <jsmith@example.com>  TRUE    FALSE    
2 J. SMITH <jsmith@example.com>    TRUE    FALSE    
3 Dr. Strage <strange@stat.ubc.ca> FALSE   FALSE    

You can also choose to manually add regex patterns to search for known patterns:

signature_add("John S(\\.|mith)", is_user = TRUE)

This will allow us to detect future commits both for “John Smith” and “John S.”. The is_user = TRUE argument specifies that John is a student, not an instructor.

Counting Points

When working on a lab from within RStudio, you can simply run:

line rubric header optional pts total prop
2 {mechanics:3} General Instructions FALSE 3 3 0.2035714
2 {reasoning:5} Exercise 1: True or False? FALSE 5 5 0.3392857
2 {reasoning:6} 2(a) FALSE 6 6 0.4071429
3 {reasoning:3} Optional 2(b) TRUE 3 3 0.2035714
3 {reasoning:3} Optional 2(c) TRUE 3 3 0.2035714

This will produce the above table (shown nicely here using knitr::kable()). If there is more than one assignment in the working directory (ending in .Rmd or .ipynb), then you will be prompted to specify which lab to analyse.

The table above shows us that there are 5 sections in this lab, and whether these points are optional or not. The total number of points is shown in the total column. Since requires questions only are meant to get you to a 95% grade, the optionals may imply a total percentage that is less than (or more) than 100% in the prop column.

For convenience, the total marks can also be tabulated via:

type total prop
Non-Optional 14 0.9500000
Optional 6 0.4071429
Total 20 1.3571429

In this fake example, we can see that the optional questions are worth a lot of marks– more than enough to get to 100% if completed.

These functions can also be called explicitly on files not in the current working directory:

count_points("~/mds/block5/dsci998/lab1/lab1.ipynb")
type total prop
Non-Optional 19 0.95
Optional 20 1.00
Total 39 1.95

Using labzenr at the Command Line

You can set an alias in your ~/.bash_profile to allow labzenr to work at the command line. We recommend:

alias checklab='Rscript -e "labzenr::check_mechanics()"'
alias points='Rscript -e "labzenr::count_points()"'

Then you can simply run

checklab

or

points

From any directory to have it print out the relevant output. Note that interactive features will not work in the same way they do in the R console.