In this post I will document the steps I take in the development of the “genero” package. A package fro inferring gender based on names in Spanish and Portuguese.
I have been using small custom functions to do just that for a couple of years, now that we want to make these type of analysis available for non-tech users through a shiny app I figured it made sense to simply put it in a package.
Let’s start then. This post in nothing more than following Emil’s usethis workflow for package development
available::available("genero")
Now that we checked the name is available I can create the package structure inside the new genero
folder with:
usethis::create_package("genero", rstudio = TRUE)
I prefer to run this straight from my terminal. Then open Rstudio with the newly created genero.Rproj
library(usethis)
usethis::use_git()
use_github(organisation = "datasketch")
use_mit_license(name = "Juan Pablo Marin Diaz")
use_readme_rmd()
I am not getting into coverage and continuous integration at this point so I am going to skip Emil’s suggestions until testthat
use_testthat() # to include tests
use_data_raw() # to include data in the package
use_data(cars) # to add cars to the package - will change later. Not exactly sure how it works
use_news_md() # to add release news for package
Now that we have our set up, let’s commit all changes (do not forget to knit your README.Rmd
) and let’s start coding.
use_r("genero") # Creat file in /R for the function
use_test("genero") # Add tests file
use_package("dplyr") # Add package dependencies
use_vignette("Guess gender from names in spanish")
Keep in mind as Emil suggests, before every commit:
- Restart R Session Cmd+Shift+F10 (Ctrl+Shift+F10 for Windows)
- Document Package Cmd+Shift+D (Ctrl+Shift+D for Windows)
- Check Package Cmd+Shift+E (Ctrl+Shift+E for Windows)
And before every release:
- Update your
README.md
by knitting yourREADME.Rmd
file - Run again documentation
devtools::document()
and checksdevtools::check()
- And update you
DESCRIPTION
and versions withuse_version()
Now it is time to code. Start editing you code, adding functions, documentation and tests.
. . .
8 hours later and after solving bugs, learning how to add data to packages, going crazy with not ascii strings, following the steps to pass the checks (described in my previous post), forgetting to update .Rbuildignore
and kniting the README.Rmd
file… I finally got to submit a my new genero
package to CRAN using:
devtools::release()
Wish me luck.