: To create a new R package designed for CRAN and having code repository maintained by git.
Just from the beginning, there are many requirements that you should fulfill for CRAN submission, you can expect that it will take two or more rounds of the submission, just you should understand that all checks matters :-) but then
https://cran.r-project.org/web/packages/gawdis
* Prepare files with R functions that should create a package (ideally one big function in one file, or couple of similar goal functions in one file).
* Choose the name, here I will mostly use
gawdis (you can see all codes on
https://github.com/pavel-fibich/gawdis ).
* [RStudio] Start with New project -> New directory -> R package in RStudio (check create git repository and choose files with R functions).
* [github] Create the same New repository on GitHub (login, create repository).
* [RStudio - git terminal] Connect your local repository to github repo
git remote add origin https://github.com/pavel-fibich/gawdis
* Now you can commit/pull to github directly in RStudio.
Because for each function and data you should have help page, it is useful to let roxygen2 (see vignettes
https://cran.r-project.org/web/packages/roxygen2/vignettes/roxygen2.html) generate help pages of the functions. Iit is quite easy and you do not need to know any Latex commands, you just annotate head of R file with #' and roxygen2 will generate Latex help for you). It done by direct calling
roxygen2::roxygenise()
Example of annotated R file, the header looks like (the last line is the R code of the function gawdis):
#' @title gawdis function
#'
#' @description \code{gawdis()}, is an extension of the function \code{gowdis}, ...
#'
#' @param x Matrix or data frame containing the variables..
#' @param W Vector listing the weights for the variables in x...
#'
#' @usage
#' gawdis(x,W = NULL, ....
#'
#' @keywords gawdis gowdis
#' @return An object of class dist ...
#' @references de Bello, F. et al. (2021) Towards a more balanced ....
#'
#' Gower, J. C. (1971) A general coefficient of similarity and ....
#'
#' @seealso gowdis() from FD package.
#' @examples
#' library(FD) # input data ...
#' x<-1
gawdis<-function(....
After the call of roxygenese() new .Rd files with help appear in man folder.
To create vignettes, you create vignettes folder with some R markdown code, that is later build for you automatically.
Building of package is easy in RStudio (you just choose Build - More - Build from source). But first, you should check it, e.g. by more strict option --as-cran, you can use RStudio too and/or check already built package
R CMD check --as-cran --no-clean packagename_0.1.0.tar.gz
It will create also pdf documentation, you should check it too. But before the submission to CRAN, you must go through checking on devel version of R (more notes on
https://cran.r-project.org/web/packages/submission_checklist.html). You can also use automatic checking on devel version of R directly on command line (or use web upload):
devtools::check_win_devel()
and you will get email in 30 minutes about the building and checks. Just to know the policy, CRAN is quite strict on checks, you should pass all of them, there are just few exceptions (eg. new package will have some warning), but you should be sure that they are not your mistake or laziness.
Mostly all the time I have problem with the length of examples (they were to long), to reduce it, you can put them inside "\donttest{code}", they will appear in help, but they are not run in checks.
If you succeed in publication of manuscript using your package, add it to references (of the functions and in DESCRIPTION file) and submit new version of your Rpackage.