Skip to content

Instantly share code, notes, and snippets.

@dcomtois
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcomtois/4bcb7b3e47bbf84605a9 to your computer and use it in GitHub Desktop.
Save dcomtois/4bcb7b3e47bbf84605a9 to your computer and use it in GitHub Desktop.
Mtl R Users Group, May 2015 - Introducing summarytools & thoughts on package development
# Presentation Mtl R Users Group, 2015-05-06
# Dominic Comtois
# Introduction à Summarytools / Introducing summarytools
# Liens / links
# https://github.com/dcomtois/summarytools
# http://www.statconseil.com
# dominic.comtois@gmail.com
# github method (need devtools installed) -- most up-to-date version of summarytools
library(devtools)
install_github("dcomtois/summarytools")
# Install via standard method -- latest stable release on official CRAN repo.
install.packages("summarytools")
# Demo
library(summarytools)
# Generate a modified iris dataset containing missing values
iris.demo <- iris
iris.nas <- matrix(as.logical(sample(FALSE:TRUE, size = 150*5, prob = c(.9,.1),replace = TRUE)),ncol = 5)
iris.demo[iris.nas] <- NA
# Ex.1: Frequency table
freq(iris.demo$Species)
# Ex.2: Descriptives
descr(iris.demo$Sepal.Length)
# Ex.3: Descriptives, multiple
descr(iris.demo)
# Ex.4: Descriptives, multiple, transposed
descr(iris.demo, transpose = TRUE)
# Ex.4: dfSummary
dfSummary(iris.demo)
# Ex.5: what.is
what.is(c)
what.is(NA)
what.is(matrix())
# Writing text files
freq(iris.demo$Species,style = "grid",
file = "mystats.txt")
dfSummary(iris.demo, style = "multiline",
file = "mystats.txt",
append = TRUE)
# Customizing Output Attributes
dfs <- dfSummary(iris.demo)
# See list of attributes
names(attributes(dfs))
# Change date and df.name
attr(dfs, "date") <- "4 Avril 2015"
attr(dfs, "df.name") <- "Iris (modifié pour fins de démonstration"
view(dfs)
# Viewing in RStudio's Viewer
print(dfSummary(iris.demo), method = "viewer")
# or equivalently:
view(dfSummary(iris.demo))
# To open in system's default browser:
view(dfSummary(iris.demo),method = "Browser")
# Notes on Package development
# - Find an inspiring package and study its source and structure
# - RStudio and GitHub are a well-integrated solution
# - GitHub is useful in many contexts and not so hard
# to learn. Definitely worth it!
# Start by understanding actions/terms "commit" and "push". The rest should
# unfold naturally.
# - To publish to CRAN, you need to read the policies
# at http://cran.r-project.org/submit.html
# - Be prepared for criticism. Learn from it, don't be discouraged by it!
# - If you don't want to fill all the requirements, just
# put your R source files on github for others to use.
# - But having a package accepted in CRAN repos is a rewarding
# experience!
# - Read on "Advanced R" website about the different OO systems
# that R has - S3, S4, RC. Pick one according to your needs.
# - Consider using roxygen
# Thanks to the organizers and participants, looking forward for next meetup!
# To learn more about me and what I do aside from programming & teaching R,
# Visit:
# www.facebook.com/DominicComtoisAtelier or www.artbangbang/DominicComtois
# www.soundcloud.com/dominic-comtois
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment