knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
The packages CNAGSCG aims at being a recollection of common functions we use in our day to day life analyzing single-cell data.
You can install the released version of CNAGSCG from GitHub with:
devtools::install_github(" Single-Cell-Genomics-Group-CNAG-CRG/CNAGSCG-package", ref = "main")
And the development version with:
# install.packages("devtools") devtools::install_github("Single-Cell-Genomics-Group-CNAG-CRG/CNAGSCG-package", ref = "devel")
If you need set the GitHub PAT in R to install the package you can set it in R by:
## set personal access token: credentials::set_github_pat("YourPAT")
Keep in mind that these being a shared package maintained by us all it is important we stick to consistent best practices so we can all read other peoples code and contribute on top of each other. When adding new functions or modifying pre-existing ones please use pull requests so someone else can check your code prior to merging in the main branch.\
Best practices on how to write an R package are detailed in Hadley Wickham's book.\
Best practices on R function writing can be found in the books R for Data Science
and the Functions chapter of Advanced R
.\
* Best practices on how to write R code can be found here and here. Use package lintr
to make sure the basic best practices are met. You can run lintr::lint_dir()
to lint a specific directory or lintr::lint_package()
to lint all the files in the package.\
New functions need to be written in an R script file following the predefined format as shown in the toy function fbind()
and saved in the R/
directory. For ease of use the R script name should be the same as the function name. This can be done by running usethis::use_r("fbind")
which will initialize the R script in the right directory.
After adding a new function make sure everything runs smoothly by:\
1- running devtools::load_all()
, this runs a mock build of the package and allows you to test the function runs correctly within the package environment. \
2- running devtools::document()
to build the documentation for the function in man/
and NAMESPACE
. Check will return error if the documentation for a function in R/
is not present. \
3- running devtools::check()
, after making sure the function runs well we need to be sure that all the moving parts of the package still work in the package environment. devtools::check()
is the equivalent of running R CMD check
in the terminal. \
4- Add a unit test for the function via usethis::use_test("fbind")
. This will open an rscript named test-fbind.R in test/testthat
. To check that all the unit tests runs properly you can run devtools::test()
. \
5- Lastly, if you add an example in README.Rmd
compile it using devtools::build_readme()
. \
Bonus, if your package requires a dependency not found the file DESCRITPION section imports you can add it by running usethis::use_package("dplyr")
.
Add examples of functions below:
library(SCrafty) library(ggplot2) library(dplyr) library(Seurat) library(GOstats)
If you are going to use Seurat object for function examples please use datasets from SeuratData
to run the vignette so we can all recreate the examples easily.
# devtools::install_github('satijalab/seurat-data') library(SeuratData)
Under development...👩💻 🧑💻
Here is a set of funtions to compute GO analysis:
gene_de <- c("MS4A1", "CD79A", "CD79B") gene_universe <- c("HLA-DRA", "AIF1", "C1QA", "LYZ", "SELENOP", "ADAMDEC1", "CD14", "CD68", "IGF1", "LGMN", "AXL", "C5AR1", "CD163", "CD163L1", "CD209", "CSF1R", "IL10", "IL10RA", "IL13RA1", "NRP1", "NRP2", "SDC3", "SIGLEC1", "TGFBI", "TGFBR1", "EEF1A1", "OAZ1", "RPL15", "RPL19", "RPS19", "RPS29", "TPT1", "UBA52", "APOE", "FCGRT", "MKI67", "PCLAF", "RRM2", "CD1C", "CLC", "IL4", "TPSAB1", "CPA3", "NRG1", "RETN", "EREG", "ACOD1", "TNIP3", "VCAN", "INHBA", "CXCL5", "HTRA1", "SPP1", "HSPA1B", "CXCR2", "PI3", "PROK2", "HSPA6", "NCCRP1", "LAD1", "CCL22", "MS4A1", "CD79A", "CD79B") GO_results <- gene_enrichment_GO( gene_de = gene_de, gene_universe = gene_universe, gene_from = "SYMBOL", gene_to = "ENTREZID", annotation = "org.Hs.eg.db", pvalue_cutoff = 0.05, test_direction = "over", ontology = "BP") knitr::kable(summary(GO_results))
Visualization... Under development...👩💻 🧑💻
With ggpreview
we can preview a plot in the viewer pane. It is very handy to find the right height and width as well as the right font size.
df <- data.frame(x = 1:10, y = 1:10) tmp_plt <- ggplot2::ggplot(df, ggplot2::aes(x = x, y = y)) + ggplot2::geom_point() CNAGSCG::ggpreview(x = tmp_plt, w = 9, h = 4)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.