a02-loading_dayoff_tutorials.Rmd
The dayoff package contains standard R vignettes (such as this one) which detail features of the package and have written tutorials on bioinformatics tasks. These are best accessed via the package website at https://brouwern.github.io/dayoff/articles/
The package also contains .Rmd tutorials which are meant to be interactive. These are all downloaded when the package is installed and can be called up using the following function.
First, you can see what tutorials are available
You can open a specific tutorial using tutor_open()
It is easiest to use tutor_show() to get a list of tutorial names and then paste the name into the tutor_open() command.
I recommend that while working through these files you save them somewhere else to preserve your work.
These tutorial files are not standard elements of an R package, so I’ve added an extra directory to the package that’s not normally there, and written the above function to load it for you. Here’s what the function is doing:
First, the function has to figure out where your copy of dayoff is located. This is done with the system.file() function.
system.file() tells you where on your computur a package happens to be located. This can vary between computers, especially between Mac, PC and Linux.
system.file(package = "dayoff")
#> [1] "C:/Users/lisanjie/AppData/Local/Temp/RtmpykxFqX/temp_libpath4836775959/dayoff"
Many R packages have a folder within them called “extdata” (“external data”) to contain things not essential to the package’s functioning. I’ll save the file path for the package to an object called dayoff.path and then call the utlity function list.files() to see what’s in the package folder.
dayoff.path <- system.file(package = "dayoff")
list.files(dayoff.path)
#> [1] "data" "DESCRIPTION"
#> [3] "extdata" "help"
#> [5] "html" "INDEX"
#> [7] "Meta" "NAMESPACE"
#> [9] "NEWS.md" "R"
#> [11] "rebuild_package_script.R" "tutorials"
I’ve made a folder called “tutorials” which is not normally in an R package
tutor.path <- paste0(dayoff.path,"/tutorials")
list.files(tutor.path)
#> [1] "AC03-01-downloading_DNA_seq_in_R.Rmd"
#> [2] "AC03-02-DNA_sequence_descriptive_stats.Rmd"
#> [3] "AC04-01-vectors.Rmd"
#> [4] "AC04-02-programming_in_R.Rmd"
#> [5] "data_frame_by_hand.Rmd"
#> [6] "data_frame_by_hand_problem_set.Rmd"
#> [7] "dayhoff_PAM_matrices.Rmd"
#> [8] "live_code_blast_via_R.Rmd"
#> [9] "NLB_alignment.Rmd"
#> [10] "NLB_worked_example_build_phylo.Rmd"
#> [11] "Pevsner_Ch4_figure4_12.Rmd"
#> [12] "Pevsner_Ch4_figure4_14.Rmd"
#> [13] "Pevsner_Ch4_figure4_14_extension.Rmd"
#> [14] "test_tutorial.Rmd"
I’ve made a function that carries out this workflow automatically
The .Rmd or .R file within the tutorials folder can be loaded by constructing the proper file name
We can double check that the file is available using file.exists()
We can then load the tutorial file by using a function called system, which allow us to specify a program (RStudio) and a file we want the program to act on.
First we need to construct a character string that specifies the program and the file
Now we can call system() and the file should open up.
This workflow is implemented by the function tutor_open