├── .Rbuildignore ├── .gitattributes ├── .gitignore ├── CODE_OF_CONDUCT.md ├── Contributing.md ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── R ├── sp_check_that_docker_is_up.R ├── sp_color_markdown_text.R ├── sp_docker_functions.R ├── sp_get_dbms_data_dictionary.R ├── sp_get_fivenumsum.R ├── sp_make_data_dictionary.R ├── sp_postgresql_functions.R ├── sp_print_df.R └── sp_show_all_docker_containers.R ├── README.Rmd ├── README.md ├── docs ├── .nojekyll ├── 404.html ├── CODE_OF_CONDUCT.html ├── Contributing.html ├── LICENSE-text.html ├── authors.html ├── docsearch.css ├── docsearch.js ├── index.html ├── link.svg ├── pkgdown.css ├── pkgdown.js ├── pkgdown.yml └── reference │ ├── index.html │ ├── sp_check_that_docker_is_up.html │ ├── sp_color_markdown_text.html │ ├── sp_docker_build.html │ ├── sp_docker_containers_tibble.html │ ├── sp_docker_images_tibble.html │ ├── sp_docker_network_create.html │ ├── sp_docker_networks_tibble.html │ ├── sp_docker_remove_container.html │ ├── sp_docker_remove_image.html │ ├── sp_docker_run.html │ ├── sp_docker_start.html │ ├── sp_docker_stop.html │ ├── sp_fetch_dvdrental_autodoc.html │ ├── sp_get_dbms_data_dictionary.html │ ├── sp_get_fivenumsum.html │ ├── sp_get_postgres_connection.html │ ├── sp_make_data_dictionary.html │ ├── sp_make_dvdrental_image.html │ ├── sp_make_simple_pg.html │ ├── sp_pg_catalog.html │ ├── sp_pg_close_connection.html │ ├── sp_pg_docker_run.html │ ├── sp_print_df.html │ └── sp_show_all_docker_containers.html ├── inst ├── extdata │ └── docker │ │ ├── Dockerfile │ │ └── restoredb.sh ├── icons │ ├── edit-sql.png │ ├── help.png │ └── postgresql.png ├── linux │ ├── arch_dependencies.bash │ ├── fedora_dependencies.bash │ └── ubuntu_dependencies.bash ├── rstudio │ ├── connections.dcf │ └── connections │ │ └── sqlpetr.R └── sql_code │ └── schemata.sql ├── man ├── sp_check_that_docker_is_up.Rd ├── sp_color_markdown_text.Rd ├── sp_docker_build.Rd ├── sp_docker_containers_tibble.Rd ├── sp_docker_images_tibble.Rd ├── sp_docker_network_create.Rd ├── sp_docker_networks_tibble.Rd ├── sp_docker_remove_container.Rd ├── sp_docker_remove_image.Rd ├── sp_docker_run.Rd ├── sp_docker_start.Rd ├── sp_docker_stop.Rd ├── sp_fetch_dvdrental_autodoc.Rd ├── sp_get_dbms_data_dictionary.Rd ├── sp_get_fivenumsum.Rd ├── sp_get_postgres_connection.Rd ├── sp_make_data_dictionary.Rd ├── sp_make_dvdrental_image.Rd ├── sp_make_simple_pg.Rd ├── sp_pg_catalog.Rd ├── sp_pg_close_connection.Rd ├── sp_pg_docker_run.Rd ├── sp_print_df.Rd └── sp_show_all_docker_containers.Rd ├── sqlpetr.Rproj └── tests ├── test_pkg.sh └── testthat ├── test_dvdrental_image.R └── test_sp_get_postgres_connection.R /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^Meta$ 2 | ^doc$ 3 | arch_install.bash 4 | CODE_OF_CONDUCT.md 5 | Contributing.md 6 | debian_ubuntu_install.bash 7 | fedora_install.bash 8 | docs 9 | install_me.R 10 | install_me_linux.R 11 | README.Rmd 12 | ^.*\.Rproj$ 13 | ^\.Rproj\.user$ 14 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Linux scripts - they need to have Linux line endings or Docker barfs 2 | *.bash text eol=lf 3 | *.sh text eol=lf 4 | 5 | *.html binary 6 | *.png binary 7 | *.pdf binary 8 | *.svg binary 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Meta 2 | doc 3 | inst/doc 4 | # This file is slightly modified from a GitHub template: 5 | # https://github.com/github/gitignore/blob/master/R.gitignore 6 | 7 | # History files 8 | .Rhistory 9 | .Rapp.history 10 | # Session Data files 11 | .RData 12 | # Example code in package build process 13 | *-Ex.R 14 | # Output files from R CMD build 15 | /*.tar.gz 16 | # Output files from R CMD check 17 | /*.Rcheck/ 18 | # RStudio files 19 | .Rproj.user 20 | # produced vignettes 21 | vignettes/*.html 22 | vignettes/*.pdf 23 | # knitr and R markdown default cache directories 24 | /*_cache/ 25 | /cache/ 26 | # Temporary files created by R markdown 27 | *.utf8.md 28 | *.knit.md 29 | # Mac OS X system files 30 | .DS_Store 31 | # github specific directories 32 | .github 33 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting any of the project maintainers. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), 71 | version 1.4, available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: sqlpetr 2 | Title: Companion Package for R-Docker-Databases Book 3 | Version: 1.1.0.9999 4 | Date: 2019-04-24 5 | Authors@R: c( 6 | person("M. Edward (Ed)", "Borasky", role = c("aut", "cre"), email = "znmeb@znmeb.net"), 7 | person("John David", "Smith", role = "aut", email = "john.smith@learningalliances.net"), 8 | person("Scott", "Came", role = "aut"), 9 | person("Jim", "Tyhurst", role = "aut"), 10 | person("Dipti", "Muni", role = "ctb"), 11 | person("Mary Anne", "Thygesen", role = "ctb"), 12 | person("Sophie", "Yang", role = "ctb"), 13 | person("Ian", "Frantz", role = "ctb")) 14 | Description: This package contains utilities for building the book and communicating with Docker and PostgreSQL. 15 | Depends: R (>= 3.4.0) 16 | License: MIT + file LICENSE 17 | Encoding: UTF-8 18 | LazyData: true 19 | Remotes: github::rstudio/gt 20 | RoxygenNote: 7.0.2 21 | Roxygen: list(markdown = TRUE) 22 | URL: https://smithjd.github.io/sqlpetr 23 | BugReports: https://github.com/smithjd/sqlpetr/issues 24 | Imports: 25 | DBI, 26 | dbplyr, 27 | dplyr, 28 | DiagrammeR, 29 | DT, 30 | glue, 31 | gt, 32 | here, 33 | inspectdf, 34 | knitr, 35 | lubridate, 36 | purrr, 37 | rmarkdown, 38 | RPostgres, 39 | RSQLite, 40 | skimr, 41 | snakecase, 42 | stringr, 43 | tibble, 44 | tidyverse, 45 | utils, 46 | readr, 47 | tsibble, 48 | fable, 49 | zoo, 50 | connections, 51 | patchwork 52 | Suggests: 53 | bookdown, 54 | devtools, 55 | formatR, 56 | ggplot2, 57 | miniUI, 58 | pkgdown, 59 | qpdf, 60 | roxygen2, 61 | testthat, 62 | usethis, 63 | webshot, 64 | xfun 65 | VignetteBuilder: knitr 66 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 John David Smith 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(sp_check_that_docker_is_up) 4 | export(sp_color_markdown_text) 5 | export(sp_docker_build) 6 | export(sp_docker_containers_tibble) 7 | export(sp_docker_images_tibble) 8 | export(sp_docker_network_create) 9 | export(sp_docker_networks_tibble) 10 | export(sp_docker_remove_container) 11 | export(sp_docker_remove_image) 12 | export(sp_docker_run) 13 | export(sp_docker_start) 14 | export(sp_docker_stop) 15 | export(sp_fetch_dvdrental_autodoc) 16 | export(sp_get_dbms_data_dictionary) 17 | export(sp_get_fivenumsum) 18 | export(sp_get_postgres_connection) 19 | export(sp_make_data_dictionary) 20 | export(sp_make_dvdrental_image) 21 | export(sp_make_simple_pg) 22 | export(sp_pg_catalog) 23 | export(sp_pg_close_connection) 24 | export(sp_pg_docker_run) 25 | export(sp_print_df) 26 | export(sp_show_all_docker_containers) 27 | importFrom(DBI,dbCanConnect) 28 | importFrom(DBI,dbClearResult) 29 | importFrom(DBI,dbColumnInfo) 30 | importFrom(DBI,dbDisconnect) 31 | importFrom(DBI,dbGetInfo) 32 | importFrom(DBI,dbGetQuery) 33 | importFrom(DBI,dbReadTable) 34 | importFrom(DBI,dbSendQuery) 35 | importFrom(DT,datatable) 36 | importFrom(RPostgres,Postgres) 37 | importFrom(dplyr,"%>%") 38 | importFrom(dplyr,bind_rows) 39 | importFrom(dplyr,collect) 40 | importFrom(dplyr,filter) 41 | importFrom(dplyr,mutate) 42 | importFrom(dplyr,select) 43 | importFrom(dplyr,tbl) 44 | importFrom(glue,glue) 45 | importFrom(knitr,kable) 46 | importFrom(purrr,map) 47 | importFrom(purrr,map_chr) 48 | importFrom(readr,col_character) 49 | importFrom(readr,cols) 50 | importFrom(readr,read_delim) 51 | importFrom(readr,read_file) 52 | importFrom(snakecase,to_snake_case) 53 | importFrom(stringr,str_detect) 54 | importFrom(tibble,as_tibble) 55 | importFrom(tibble,tibble) 56 | importFrom(utils,browseURL) 57 | -------------------------------------------------------------------------------- /R/sp_check_that_docker_is_up.R: -------------------------------------------------------------------------------- 1 | #' Check that docker is running 2 | #' 3 | #' @return 0 4 | #' @importFrom stringr str_detect 5 | #' @export 6 | #' 7 | #' @examples 8 | #' \dontrun{sp_check_that_docker_is_up()} 9 | sp_check_that_docker_is_up <- function() { 10 | response <- system2("docker", "ps ", stdout = TRUE, stderr = TRUE) 11 | if (length(response) == 1) { 12 | message <- ifelse(str_detect(response[[1]],"CONTAINER.+CREATED.+NAMES"), 13 | "Docker is up but running no containers", 14 | response[[1]]) 15 | } else { 16 | message <- c("Docker is up, running these containers:", response) 17 | } 18 | message 19 | } 20 | -------------------------------------------------------------------------------- /R/sp_color_markdown_text.R: -------------------------------------------------------------------------------- 1 | #' Color subsequent text in a specified color 2 | #' 3 | #' @param x a string 4 | #' @param color color to apply 5 | #' 6 | #' @return colored string 7 | #' @export 8 | #' 9 | #' @examples # sp_color_markdown_text('Cover inline tables in future section','red') 10 | sp_color_markdown_text <- function(x,color) 11 | { 12 | outputFormat = knitr::opts_knit$get("rmarkdown.pandoc.to") 13 | if (outputFormat == 'latex') 14 | paste0("\\textcolor{",color,"}{",x,"}") 15 | else if (outputFormat == 'html') 16 | paste0("",x,"") 17 | else 18 | x 19 | } 20 | -------------------------------------------------------------------------------- /R/sp_get_dbms_data_dictionary.R: -------------------------------------------------------------------------------- 1 | #' Download a table from the dbms and create a data dictionary data frame 2 | #' 3 | #' @param table_name The name of a table to be processed. 4 | #' @param con A DBI connection object for obtaining the local copy to be processed 5 | #' 6 | #' @return a data frame `table_dd` 7 | #' @export 8 | #' @importFrom dplyr %>% 9 | #' @importFrom dplyr tbl 10 | #' @importFrom dplyr collect 11 | #' 12 | #' @examples 13 | #' \dontrun{all_meta <- sp_get_dbms_data_dictionary("rental")} 14 | sp_get_dbms_data_dictionary <- function(table_name, con = con) { 15 | table_ptr <- tbl(con, table_name) 16 | local_df <- table_ptr %>% collect(n = Inf) 17 | table_dd <- sp_make_data_dictionary(local_df, df_alias = table_name) 18 | } 19 | -------------------------------------------------------------------------------- /R/sp_get_fivenumsum.R: -------------------------------------------------------------------------------- 1 | #' Calculate a 5 number summary (for all types of variables) 2 | #' 3 | #' @param var The variable to be summarized 4 | #' @param character_truncate_length the length of output character summaries (for ) 5 | #' 6 | #' @return The min, max, median, and 25th and 75th percentiles 7 | #' @export 8 | #' @importFrom tibble as_tibble 9 | #' @importFrom tibble tibble 10 | #' 11 | #' @examples summary_vector <- sp_get_fivenumsum(mtcars$mpg) 12 | sp_get_fivenumsum <- function(var, character_truncate_length = 60){ 13 | # emulate fivenum function for characters, numerics and POSIXct 14 | # if the values of a variable are all missing, this function crashes 15 | num_rows <- length(var) 16 | # handle SQL "missing value" for dates... 17 | # var <- ifelse(is.character(var) & 18 | # (var == "0000-00-00 00:00:00" | var == "0000-00-00"), "", var) 19 | # var <- parse_guess(var) 20 | non_blanks <- var[!is.na(var)] 21 | non_missing_n <- length(non_blanks) 22 | if (non_missing_n == 0) { 23 | summary <- tibble(num_rows = num_rows, num_blank = num_rows, num_unique = 0, 24 | min = "", q_25 = "", q_50 = "", q_75 = "", max = "") 25 | return(summary) 26 | } else if (non_missing_n == 1) { 27 | summary <- tibble(num_rows = num_rows, num_blank = num_rows, num_unique = 1, 28 | min = "", q_25 = "", q_50 = as.character(non_blanks[1]), 29 | q_75 = "", max = "") 30 | # summary$q_50 = as.character(non_blanks[1]) 31 | return(summary) 32 | } else if (non_missing_n == 2) { 33 | ordered <- non_blanks[order(non_blanks)] 34 | summary <- tibble(num_rows = num_rows, num_blank = sum(is.na(var)), 35 | num_unique = length(unique(non_blanks)), 36 | min = as.character(ordered[1]), 37 | q_25 = as.character(ordered[1]), q_50 = "", 38 | q_75 = as.character(ordered[2]), 39 | max = as.character(ordered[2])) 40 | return(summary) 41 | } else if (non_missing_n == 3) { 42 | ordered <- non_blanks[order(non_blanks)] 43 | summary <- tibble(num_rows = num_rows, num_blank = sum(is.na(var)), 44 | num_unique = length(unique(non_blanks)), 45 | min = as.character(ordered[1]), 46 | q_25 = as.character(ordered[1]), 47 | q_50 = as.character(ordered[2]), 48 | q_75 = as.character(ordered[3]), 49 | max = as.character(ordered[3])) 50 | return(summary) 51 | } 52 | else { 53 | # num_blank <- ifelse(is.Date(var), 54 | # sum(is.na(var)), 55 | # sum(var == "")) 56 | num_blank <- sum(is.na(var)) 57 | num_unique <- length(unique(non_blanks)) 58 | med_pos <- round((max(1,non_missing_n/2)),0) 59 | qrt_pos <- round((max(1,non_missing_n/4)),0) 60 | ordered <- non_blanks[order(non_blanks)] 61 | min <- ordered[1] 62 | q_25 <- ordered[(med_pos - qrt_pos)] 63 | q_50 <- ordered[med_pos] 64 | q_75 <- ordered[(med_pos + qrt_pos)] 65 | max <- ordered[non_missing_n] 66 | summary <- 67 | tibble(num_rows, num_blank, num_unique, 68 | min = substr(as.character(min), 1, character_truncate_length), 69 | q_25 = substr(as.character(q_25), 1, character_truncate_length), 70 | q_50 = substr(as.character(q_50), 1, character_truncate_length), 71 | q_75 = substr(as.character(q_75), 1, character_truncate_length), 72 | max = substr(as.character(max), 1, character_truncate_length)) 73 | return(summary) 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /R/sp_make_data_dictionary.R: -------------------------------------------------------------------------------- 1 | #' Run sp_get_fivenumsum on all variables in a data frame 2 | #' 3 | #' @param df data frame to be summarized 4 | #' @param df_alias name of the data frame to be appended 5 | #' 6 | #' @return a data frame 7 | #' @export 8 | #' @importFrom tibble as_tibble 9 | #' @importFrom tibble tibble 10 | #' @importFrom purrr map 11 | #' @importFrom purrr map_chr 12 | #' 13 | #' @examples table_dd <- sp_make_data_dictionary(mtcars) 14 | sp_make_data_dictionary <- function(df, df_alias = NULL){ 15 | df_name <- substitute(df) 16 | if (!is.null(df_alias)) {df_name <- df_alias} 17 | n_of_vars_in_df <- dim(df)[2] 18 | data_frame_info <- tibble::as_tibble(rep(as.character(df_name),n_of_vars_in_df)) 19 | var_name_list <- as.character(names(df)) 20 | fivesum <- purrr::map(df,sp_get_fivenumsum) %>% dplyr::bind_rows() 21 | fivesum <- dplyr::bind_cols(tibble::tibble(var_name = var_name_list), fivesum) 22 | var_type_info <- tibble::tibble(var_name = names(df), var_type = purrr::map_chr(df, typeof)) 23 | names(data_frame_info) <- "table_name" 24 | dd_out <- dplyr::left_join(var_type_info, fivesum, by = "var_name") 25 | dd_out <- dplyr::bind_cols(data_frame_info,dd_out) 26 | dd_out 27 | } 28 | -------------------------------------------------------------------------------- /R/sp_print_df.R: -------------------------------------------------------------------------------- 1 | #' Show (print) a data frame depending on appropriate output type 2 | #' 3 | #' @param df the data frame to be shown 4 | #' 5 | #' @return either kable (in PDF) or datatable (in HTML) output 6 | #' @importFrom DT datatable 7 | #' @importFrom knitr kable 8 | #' @export 9 | #' 10 | #' @examples 11 | #' \dontrun{sp_print_df(df)} 12 | sp_print_df <- function(df){ 13 | if (knitr::is_latex_output()) { 14 | knitr::kable(df) 15 | } else { 16 | DT::datatable(df) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /R/sp_show_all_docker_containers.R: -------------------------------------------------------------------------------- 1 | #' Check that docker is running 2 | #' 3 | #' @return 0 4 | #' @export 5 | #' 6 | #' @examples 7 | #' \dontrun{sp_show_all_docker_containers()} 8 | sp_show_all_docker_containers <- function() { 9 | response <- system2("docker", "ps -a ", 10 | stdout = TRUE, stderr = FALSE) 11 | response_length <- length(response) 12 | if (response_length == 1) { 13 | stop("There are no Docker containers running") 14 | } 15 | cat(response, sep = "\n") 16 | } 17 | -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "sqlpetr" 3 | output: github_document 4 | --- 5 | 6 | ```{r setup, include=FALSE} 7 | knitr::opts_chunk$set(echo = TRUE) 8 | ``` 9 | 10 | ## Introduction 11 | `sqlpetr` is the companion R package for the database tutorial eBook at . It has two classes of functions: 12 | 13 | 1. Functions to install the dependencies needed to build the book and perform the operations covered in the tutorial, and 14 | 2. Utilities for dealing with Docker and the PostgreSQL Docker image we use. 15 | 16 | `sqlpetr` has a `pkgdown` site at . 17 | 18 | ## Prerequisites 19 | You will need the following software: 20 | 21 | 1. R 3.4.0 or later: 22 | * For Windows, go to . 23 | * For MacOS, go to . 24 | 2. RStudio Preview 1.2.1330 or later (). 25 | 3. Docker: 26 | * For Windows 10 Pro, use Docker for Windows (). 27 | * For other versions of Windows, use Docker Toolbox (). 28 | * For MacOS El Capitan 10.11 or newer macOS release running on a 2010 or newer Mac, with Intel’s hardware support for MMU virtualization, use Docker for Mac (). 29 | * For other versions of MacOS, use Docker Toolbox (). 30 | 31 | See below for the details if you're a Linux desktop user. 32 | 33 | ## Installing this package for users of 34 | If you are working through the code in the book, you will need to install this package first. Note that these instructions assume Windows or MacOS. For Linux, you will need to install some Linux packages. See below for the details on Ubuntu, Fedora or Arch Linux. 35 | 36 | 1. Make sure you have a writeable personal library. 37 | 2. Update all your packages with `update.packages()`. 38 | 3. Install `remotes` if you haven't already. 39 | 4. In an R console, type 40 | 41 | ``` 42 | remotes::install_github("smithjd/sqlpetr", force = TRUE, build = FALSE, quiet = TRUE) 43 | ``` 44 | 45 | ## Linux desktop 46 | We support Ubuntu Linux 18.04 LTS ("Bionic Beaver") or later, Fedora 28 or later and Arch Linux. You will need to install RStudio yourself, but we provide scripts to install all the other Linux dependencies including R and Docker. 47 | 48 | 1. Install Linux - any desktop should work. 49 | 2. Browse to . You will find install scripts for Ubuntu, Fedora and Arch. Download the one for your distro, make it executable and run it. The script will install R and the Linux dependencies for `sqlpetr`, install Docker, add you to the `docker` group and enable/start the Docker service. 50 | 3. Now do 51 | 52 | ``` 53 | remotes::install_github("smithjd/sqlpetr", force = TRUE, build = FALSE, quiet = TRUE) 54 | ``` 55 | 56 | to install `sqlpetr`. 57 | 58 | Note that you will need to log out back to the display manager prompt and log back in for Docker commands to work without `sudo`. 59 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | sqlpetr 2 | ================ 3 | 4 | ## Introduction 5 | 6 | `sqlpetr` is the companion R package for the database tutorial eBook at 7 | . It has two classes of functions: 8 | 9 | 1. Functions to install the dependencies needed to build the book and 10 | perform the operations covered in the tutorial, and 11 | 2. Utilities for dealing with Docker and the PostgreSQL Docker image we 12 | use. 13 | 14 | `sqlpetr` has a `pkgdown` site at . 15 | 16 | ## Prerequisites 17 | 18 | You will need the following software: 19 | 20 | 1. R 3.4.0 or later: 21 | - For Windows, go to . 22 | - For MacOS, go to . 23 | 2. RStudio Preview 1.2.1330 or later 24 | (). 25 | 3. Docker: 26 | - For Windows 10 Pro, use Docker for Windows 27 | (). 28 | - For other versions of Windows, use Docker Toolbox 29 | (). 30 | - For MacOS El Capitan 10.11 or newer macOS release running on a 31 | 2010 or newer Mac, with Intel’s hardware support for MMU 32 | virtualization, use Docker for Mac 33 | (). 34 | - For other versions of MacOS, use Docker Toolbox 35 | (). 36 | 37 | See below for the details if you’re a Linux desktop 38 | user. 39 | 40 | ## Installing this package for users of 41 | 42 | If you are working through the code in the book, you will need to 43 | install this package first. Note that these instructions assume Windows 44 | or MacOS. For Linux, you will need to install some Linux packages. See 45 | below for the details on Ubuntu, Fedora or Arch Linux. 46 | 47 | 1. Make sure you have a writeable personal library. 48 | 49 | 2. Update all your packages with `update.packages()`. 50 | 51 | 3. Install `remotes` if you haven’t already. 52 | 53 | 4. In an R console, 54 | type 55 | 56 | remotes::install_github("smithjd/sqlpetr", force = TRUE, build = FALSE, quiet = TRUE) 57 | 58 | ## Linux desktop 59 | 60 | We support Ubuntu Linux 18.04 LTS (“Bionic Beaver”) or later, Fedora 28 61 | or later and Arch Linux. You will need to install RStudio yourself, but 62 | we provide scripts to install all the other Linux dependencies including 63 | R and Docker. 64 | 65 | 1. Install Linux - any desktop should work. 66 | 67 | 2. Browse to 68 | . You 69 | will find install scripts for Ubuntu, Fedora and Arch. Download the 70 | one for your distro, make it executable and run it. The script will 71 | install R and the Linux dependencies for `sqlpetr`, install Docker, 72 | add you to the `docker` group and enable/start the Docker service. 73 | 74 | 3. Now 75 | do 76 | 77 | remotes::install_github("smithjd/sqlpetr", force = TRUE, build = FALSE, quiet = TRUE) 78 | 79 | to install `sqlpetr`. 80 | 81 | Note that you will need to log out back to the display manager prompt 82 | and log back in for Docker commands to work without `sudo`. 83 | -------------------------------------------------------------------------------- /docs/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smithjd/sqlpetr/f73cdbae569cb5a2c9f6231a513156da308e2192/docs/.nojekyll -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Page not found (404) • sqlpetr 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 51 | 52 | 53 | 54 | 55 | 56 | 57 |
58 |
59 | 93 | 94 | 95 | 96 |
97 | 98 |
99 |
100 | 103 | 104 | Content not found. Please use links in the navbar. 105 | 106 |
107 | 108 |
109 | 110 | 111 | 112 |
113 | 116 | 117 |
118 |

Site built with pkgdown 1.4.1.

119 |
120 | 121 |
122 |
123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | -------------------------------------------------------------------------------- /docs/LICENSE-text.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | License • sqlpetr 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 51 | 52 | 53 | 54 | 55 | 56 | 57 |
58 |
59 | 93 | 94 | 95 | 96 |
97 | 98 |
99 |
100 | 103 | 104 |
MIT License
105 | 
106 | Copyright (c) 2018 John David Smith
107 | 
108 | Permission is hereby granted, free of charge, to any person obtaining a copy
109 | of this software and associated documentation files (the "Software"), to deal
110 | in the Software without restriction, including without limitation the rights
111 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
112 | copies of the Software, and to permit persons to whom the Software is
113 | furnished to do so, subject to the following conditions:
114 | 
115 | The above copyright notice and this permission notice shall be included in all
116 | copies or substantial portions of the Software.
117 | 
118 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
119 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
120 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
121 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
122 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
123 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
124 | SOFTWARE.
125 | 
126 | 127 |
128 | 129 |
130 | 131 | 132 | 133 |
134 | 137 | 138 |
139 |

Site built with pkgdown 1.4.1.

140 |
141 | 142 |
143 |
144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /docs/authors.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Authors • sqlpetr 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 51 | 52 | 53 | 54 | 55 | 56 | 57 |
58 |
59 | 93 | 94 | 95 | 96 |
97 | 98 |
99 |
100 | 103 | 104 |
    105 |
  • 106 |

    M. Edward (Ed) Borasky. Author, maintainer. 107 |

    108 |
  • 109 |
  • 110 |

    John David Smith. Author. 111 |

    112 |
  • 113 |
  • 114 |

    Scott Came. Author. 115 |

    116 |
  • 117 |
  • 118 |

    Jim Tyhurst. Author. 119 |

    120 |
  • 121 |
  • 122 |

    Dipti Muni. Contributor. 123 |

    124 |
  • 125 |
  • 126 |

    Mary Anne Thygesen. Contributor. 127 |

    128 |
  • 129 |
  • 130 |

    Sophie Yang. Contributor. 131 |

    132 |
  • 133 |
  • 134 |

    Ian Frantz. Contributor. 135 |

    136 |
  • 137 |
138 | 139 |
140 | 141 |
142 | 143 | 144 | 145 |
146 | 149 | 150 |
151 |

Site built with pkgdown 1.4.1.

152 |
153 | 154 |
155 |
156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | -------------------------------------------------------------------------------- /docs/docsearch.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // register a handler to move the focus to the search bar 4 | // upon pressing shift + "/" (i.e. "?") 5 | $(document).on('keydown', function(e) { 6 | if (e.shiftKey && e.keyCode == 191) { 7 | e.preventDefault(); 8 | $("#search-input").focus(); 9 | } 10 | }); 11 | 12 | $(document).ready(function() { 13 | // do keyword highlighting 14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ 15 | var mark = function() { 16 | 17 | var referrer = document.URL ; 18 | var paramKey = "q" ; 19 | 20 | if (referrer.indexOf("?") !== -1) { 21 | var qs = referrer.substr(referrer.indexOf('?') + 1); 22 | var qs_noanchor = qs.split('#')[0]; 23 | var qsa = qs_noanchor.split('&'); 24 | var keyword = ""; 25 | 26 | for (var i = 0; i < qsa.length; i++) { 27 | var currentParam = qsa[i].split('='); 28 | 29 | if (currentParam.length !== 2) { 30 | continue; 31 | } 32 | 33 | if (currentParam[0] == paramKey) { 34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); 35 | } 36 | } 37 | 38 | if (keyword !== "") { 39 | $(".contents").unmark({ 40 | done: function() { 41 | $(".contents").mark(keyword); 42 | } 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | mark(); 49 | }); 50 | }); 51 | 52 | /* Search term highlighting ------------------------------*/ 53 | 54 | function matchedWords(hit) { 55 | var words = []; 56 | 57 | var hierarchy = hit._highlightResult.hierarchy; 58 | // loop to fetch from lvl0, lvl1, etc. 59 | for (var idx in hierarchy) { 60 | words = words.concat(hierarchy[idx].matchedWords); 61 | } 62 | 63 | var content = hit._highlightResult.content; 64 | if (content) { 65 | words = words.concat(content.matchedWords); 66 | } 67 | 68 | // return unique words 69 | var words_uniq = [...new Set(words)]; 70 | return words_uniq; 71 | } 72 | 73 | function updateHitURL(hit) { 74 | 75 | var words = matchedWords(hit); 76 | var url = ""; 77 | 78 | if (hit.anchor) { 79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; 80 | } else { 81 | url = hit.url + '?q=' + escape(words.join(" ")); 82 | } 83 | 84 | return url; 85 | } 86 | -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /docs/pkgdown.css: -------------------------------------------------------------------------------- 1 | /* Sticky footer */ 2 | 3 | /** 4 | * Basic idea: https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/ 5 | * Details: https://github.com/philipwalton/solved-by-flexbox/blob/master/assets/css/components/site.css 6 | * 7 | * .Site -> body > .container 8 | * .Site-content -> body > .container .row 9 | * .footer -> footer 10 | * 11 | * Key idea seems to be to ensure that .container and __all its parents__ 12 | * have height set to 100% 13 | * 14 | */ 15 | 16 | html, body { 17 | height: 100%; 18 | } 19 | 20 | body > .container { 21 | display: flex; 22 | height: 100%; 23 | flex-direction: column; 24 | } 25 | 26 | body > .container .row { 27 | flex: 1 0 auto; 28 | } 29 | 30 | footer { 31 | margin-top: 45px; 32 | padding: 35px 0 36px; 33 | border-top: 1px solid #e5e5e5; 34 | color: #666; 35 | display: flex; 36 | flex-shrink: 0; 37 | } 38 | footer p { 39 | margin-bottom: 0; 40 | } 41 | footer div { 42 | flex: 1; 43 | } 44 | footer .pkgdown { 45 | text-align: right; 46 | } 47 | footer p { 48 | margin-bottom: 0; 49 | } 50 | 51 | img.icon { 52 | float: right; 53 | } 54 | 55 | img { 56 | max-width: 100%; 57 | } 58 | 59 | /* Fix bug in bootstrap (only seen in firefox) */ 60 | summary { 61 | display: list-item; 62 | } 63 | 64 | /* Typographic tweaking ---------------------------------*/ 65 | 66 | .contents .page-header { 67 | margin-top: calc(-60px + 1em); 68 | } 69 | 70 | /* Section anchors ---------------------------------*/ 71 | 72 | a.anchor { 73 | margin-left: -30px; 74 | display:inline-block; 75 | width: 30px; 76 | height: 30px; 77 | visibility: hidden; 78 | 79 | background-image: url(./link.svg); 80 | background-repeat: no-repeat; 81 | background-size: 20px 20px; 82 | background-position: center center; 83 | } 84 | 85 | .hasAnchor:hover a.anchor { 86 | visibility: visible; 87 | } 88 | 89 | @media (max-width: 767px) { 90 | .hasAnchor:hover a.anchor { 91 | visibility: hidden; 92 | } 93 | } 94 | 95 | 96 | /* Fixes for fixed navbar --------------------------*/ 97 | 98 | .contents h1, .contents h2, .contents h3, .contents h4 { 99 | padding-top: 60px; 100 | margin-top: -40px; 101 | } 102 | 103 | /* Sidebar --------------------------*/ 104 | 105 | #sidebar { 106 | margin-top: 30px; 107 | position: -webkit-sticky; 108 | position: sticky; 109 | top: 70px; 110 | } 111 | #sidebar h2 { 112 | font-size: 1.5em; 113 | margin-top: 1em; 114 | } 115 | 116 | #sidebar h2:first-child { 117 | margin-top: 0; 118 | } 119 | 120 | #sidebar .list-unstyled li { 121 | margin-bottom: 0.5em; 122 | } 123 | 124 | .orcid { 125 | height: 16px; 126 | /* margins are required by official ORCID trademark and display guidelines */ 127 | margin-left:4px; 128 | margin-right:4px; 129 | vertical-align: middle; 130 | } 131 | 132 | /* Reference index & topics ----------------------------------------------- */ 133 | 134 | .ref-index th {font-weight: normal;} 135 | 136 | .ref-index td {vertical-align: top;} 137 | .ref-index .icon {width: 40px;} 138 | .ref-index .alias {width: 40%;} 139 | .ref-index-icons .alias {width: calc(40% - 40px);} 140 | .ref-index .title {width: 60%;} 141 | 142 | .ref-arguments th {text-align: right; padding-right: 10px;} 143 | .ref-arguments th, .ref-arguments td {vertical-align: top;} 144 | .ref-arguments .name {width: 20%;} 145 | .ref-arguments .desc {width: 80%;} 146 | 147 | /* Nice scrolling for wide elements --------------------------------------- */ 148 | 149 | table { 150 | display: block; 151 | overflow: auto; 152 | } 153 | 154 | /* Syntax highlighting ---------------------------------------------------- */ 155 | 156 | pre { 157 | word-wrap: normal; 158 | word-break: normal; 159 | border: 1px solid #eee; 160 | } 161 | 162 | pre, code { 163 | background-color: #f8f8f8; 164 | color: #333; 165 | } 166 | 167 | pre code { 168 | overflow: auto; 169 | word-wrap: normal; 170 | white-space: pre; 171 | } 172 | 173 | pre .img { 174 | margin: 5px 0; 175 | } 176 | 177 | pre .img img { 178 | background-color: #fff; 179 | display: block; 180 | height: auto; 181 | } 182 | 183 | code a, pre a { 184 | color: #375f84; 185 | } 186 | 187 | a.sourceLine:hover { 188 | text-decoration: none; 189 | } 190 | 191 | .fl {color: #1514b5;} 192 | .fu {color: #000000;} /* function */ 193 | .ch,.st {color: #036a07;} /* string */ 194 | .kw {color: #264D66;} /* keyword */ 195 | .co {color: #888888;} /* comment */ 196 | 197 | .message { color: black; font-weight: bolder;} 198 | .error { color: orange; font-weight: bolder;} 199 | .warning { color: #6A0366; font-weight: bolder;} 200 | 201 | /* Clipboard --------------------------*/ 202 | 203 | .hasCopyButton { 204 | position: relative; 205 | } 206 | 207 | .btn-copy-ex { 208 | position: absolute; 209 | right: 0; 210 | top: 0; 211 | visibility: hidden; 212 | } 213 | 214 | .hasCopyButton:hover button.btn-copy-ex { 215 | visibility: visible; 216 | } 217 | 218 | /* headroom.js ------------------------ */ 219 | 220 | .headroom { 221 | will-change: transform; 222 | transition: transform 200ms linear; 223 | } 224 | .headroom--pinned { 225 | transform: translateY(0%); 226 | } 227 | .headroom--unpinned { 228 | transform: translateY(-100%); 229 | } 230 | 231 | /* mark.js ----------------------------*/ 232 | 233 | mark { 234 | background-color: rgba(255, 255, 51, 0.5); 235 | border-bottom: 2px solid rgba(255, 153, 51, 0.3); 236 | padding: 1px; 237 | } 238 | 239 | /* vertical spacing after htmlwidgets */ 240 | .html-widget { 241 | margin-bottom: 10px; 242 | } 243 | 244 | /* fontawesome ------------------------ */ 245 | 246 | .fab { 247 | font-family: "Font Awesome 5 Brands" !important; 248 | } 249 | 250 | /* don't display links in code chunks when printing */ 251 | /* source: https://stackoverflow.com/a/10781533 */ 252 | @media print { 253 | code a:link:after, code a:visited:after { 254 | content: ""; 255 | } 256 | } 257 | -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | /* http://gregfranko.com/blog/jquery-best-practices/ */ 2 | (function($) { 3 | $(function() { 4 | 5 | $('.navbar-fixed-top').headroom(); 6 | 7 | $('body').css('padding-top', $('.navbar').height() + 10); 8 | $(window).resize(function(){ 9 | $('body').css('padding-top', $('.navbar').height() + 10); 10 | }); 11 | 12 | $('body').scrollspy({ 13 | target: '#sidebar', 14 | offset: 60 15 | }); 16 | 17 | $('[data-toggle="tooltip"]').tooltip(); 18 | 19 | var cur_path = paths(location.pathname); 20 | var links = $("#navbar ul li a"); 21 | var max_length = -1; 22 | var pos = -1; 23 | for (var i = 0; i < links.length; i++) { 24 | if (links[i].getAttribute("href") === "#") 25 | continue; 26 | // Ignore external links 27 | if (links[i].host !== location.host) 28 | continue; 29 | 30 | var nav_path = paths(links[i].pathname); 31 | 32 | var length = prefix_length(nav_path, cur_path); 33 | if (length > max_length) { 34 | max_length = length; 35 | pos = i; 36 | } 37 | } 38 | 39 | // Add class to parent
  • , and enclosing
  • if in dropdown 40 | if (pos >= 0) { 41 | var menu_anchor = $(links[pos]); 42 | menu_anchor.parent().addClass("active"); 43 | menu_anchor.closest("li.dropdown").addClass("active"); 44 | } 45 | }); 46 | 47 | function paths(pathname) { 48 | var pieces = pathname.split("/"); 49 | pieces.shift(); // always starts with / 50 | 51 | var end = pieces[pieces.length - 1]; 52 | if (end === "index.html" || end === "") 53 | pieces.pop(); 54 | return(pieces); 55 | } 56 | 57 | // Returns -1 if not found 58 | function prefix_length(needle, haystack) { 59 | if (needle.length > haystack.length) 60 | return(-1); 61 | 62 | // Special case for length-0 haystack, since for loop won't run 63 | if (haystack.length === 0) { 64 | return(needle.length === 0 ? 0 : -1); 65 | } 66 | 67 | for (var i = 0; i < haystack.length; i++) { 68 | if (needle[i] != haystack[i]) 69 | return(i); 70 | } 71 | 72 | return(haystack.length); 73 | } 74 | 75 | /* Clipboard --------------------------*/ 76 | 77 | function changeTooltipMessage(element, msg) { 78 | var tooltipOriginalTitle=element.getAttribute('data-original-title'); 79 | element.setAttribute('data-original-title', msg); 80 | $(element).tooltip('show'); 81 | element.setAttribute('data-original-title', tooltipOriginalTitle); 82 | } 83 | 84 | if(ClipboardJS.isSupported()) { 85 | $(document).ready(function() { 86 | var copyButton = ""; 87 | 88 | $(".examples, div.sourceCode").addClass("hasCopyButton"); 89 | 90 | // Insert copy buttons: 91 | $(copyButton).prependTo(".hasCopyButton"); 92 | 93 | // Initialize tooltips: 94 | $('.btn-copy-ex').tooltip({container: 'body'}); 95 | 96 | // Initialize clipboard: 97 | var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { 98 | text: function(trigger) { 99 | return trigger.parentNode.textContent; 100 | } 101 | }); 102 | 103 | clipboardBtnCopies.on('success', function(e) { 104 | changeTooltipMessage(e.trigger, 'Copied!'); 105 | e.clearSelection(); 106 | }); 107 | 108 | clipboardBtnCopies.on('error', function() { 109 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); 110 | }); 111 | }); 112 | } 113 | })(window.jQuery || window.$) 114 | -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: 2.9.1.1 2 | pkgdown: 1.4.1 3 | pkgdown_sha: ~ 4 | articles: [] 5 | 6 | -------------------------------------------------------------------------------- /docs/reference/sp_check_that_docker_is_up.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Check that docker is running — sp_check_that_docker_is_up • sqlpetr 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
    60 |
    61 | 95 | 96 | 97 | 98 |
    99 | 100 |
    101 |
    102 | 107 | 108 |
    109 |

    Check that docker is running

    110 |
    111 | 112 |
    sp_check_that_docker_is_up()
    113 | 114 | 115 |

    Value

    116 | 117 |

    0

    118 | 119 |

    Examples

    120 |
    if (FALSE) sp_check_that_docker_is_up()
    121 |
    122 | 130 |
    131 | 132 | 133 |
    134 | 137 | 138 |
    139 |

    Site built with pkgdown 1.4.1.

    140 |
    141 | 142 |
    143 |
    144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /docs/reference/sp_color_markdown_text.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Color subsequent text in a specified color — sp_color_markdown_text • sqlpetr 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
    60 |
    61 | 95 | 96 | 97 | 98 |
    99 | 100 |
    101 |
    102 | 107 | 108 |
    109 |

    Color subsequent text in a specified color

    110 |
    111 | 112 |
    sp_color_markdown_text(x, color)
    113 | 114 |

    Arguments

    115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 |
    x

    a string

    color

    color to apply

    126 | 127 |

    Value

    128 | 129 |

    colored string

    130 | 131 |

    Examples

    132 |
    # sp_color_markdown_text('Cover inline tables in future section','red') 133 |
    134 |
    135 | 144 |
    145 | 146 | 147 |
    148 | 151 | 152 |
    153 |

    Site built with pkgdown 1.4.1.

    154 |
    155 | 156 |
    157 |
    158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | -------------------------------------------------------------------------------- /docs/reference/sp_docker_build.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Build a Docker image — sp_docker_build • sqlpetr 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
    60 |
    61 | 95 | 96 | 97 | 98 |
    99 | 100 |
    101 |
    102 | 107 | 108 |
    109 |

    Creates a Docker image

    110 |
    111 | 112 |
    sp_docker_build(build_options, build_context_path)
    113 | 114 |

    Arguments

    115 | 116 | 117 | 118 | 119 | 122 | 123 | 124 | 125 | 126 | 127 |
    build_options

    character: the build options. There are many; do 120 | docker build --help at a command prompt to see them. You will need at least 121 | the --tag option to give the built image a tag (name).

    build_context_path

    character: the build context path

    128 | 129 |

    Value

    130 | 131 |

    Result of Docker command if it succeeded. Stops with an error message 132 | if it failed.

    133 | 134 |
    135 | 143 |
    144 | 145 | 146 |
    147 | 150 | 151 |
    152 |

    Site built with pkgdown 1.4.1.

    153 |
    154 | 155 |
    156 |
    157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /docs/reference/sp_docker_containers_tibble.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | List containers into a tibble — sp_docker_containers_tibble • sqlpetr 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
    60 |
    61 | 95 | 96 | 97 | 98 |
    99 | 100 |
    101 |
    102 | 107 | 108 |
    109 |

    Creates a tibble of containers using docker ps

    110 |
    111 | 112 |
    sp_docker_containers_tibble(list_all = FALSE)
    113 | 114 |

    Arguments

    115 | 116 | 117 | 118 | 119 | 121 | 122 |
    list_all

    logical: list all containers if TRUE, just 120 | running containers if FALSE. Default is FALSE.

    123 | 124 |

    Value

    125 | 126 |

    A tibble listing the containers. If there are none, 127 | returns an empty (0x0) tibble.

    128 | 129 |

    Examples

    130 |
    if (FALSE) { 131 | sp_docker_containers_tibble(list_all = FALSE) 132 | }
    133 |
    134 | 143 |
    144 | 145 | 146 |
    147 | 150 | 151 |
    152 |

    Site built with pkgdown 1.4.1.

    153 |
    154 | 155 |
    156 |
    157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /docs/reference/sp_docker_images_tibble.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | List images into a tibble — sp_docker_images_tibble • sqlpetr 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
    60 |
    61 | 95 | 96 | 97 | 98 |
    99 | 100 |
    101 |
    102 | 107 | 108 |
    109 |

    Creates a tibble of images using docker images

    110 |
    111 | 112 |
    sp_docker_images_tibble(list_all = FALSE)
    113 | 114 |

    Arguments

    115 | 116 | 117 | 118 | 119 | 121 | 122 |
    list_all

    logical: list all images if TRUE, just 120 | tagged images if FALSE. Default is FALSE.

    123 | 124 |

    Value

    125 | 126 |

    A tibble listing the images

    127 | 128 |

    Examples

    129 |
    if (FALSE) { 130 | sp_docker_images_tibble(list_all = FALSE) 131 | }
    132 |
    133 | 142 |
    143 | 144 | 145 |
    146 | 149 | 150 |
    151 |

    Site built with pkgdown 1.4.1.

    152 |
    153 | 154 |
    155 |
    156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | -------------------------------------------------------------------------------- /docs/reference/sp_docker_network_create.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Create a Docker network — sp_docker_network_create • sqlpetr 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
    60 |
    61 | 95 | 96 | 97 | 98 |
    99 | 100 |
    101 |
    102 | 107 | 108 |
    109 |

    Creates a Docker network with name network_name.

    110 |
    111 | 112 |
    sp_docker_network_create(network_name = "sql-pet")
    113 | 114 |

    Arguments

    115 | 116 | 117 | 118 | 119 | 120 | 121 |
    network_name

    character: network to create. The default is sql-pet.

    122 | 123 |

    Value

    124 | 125 |

    Result of Docker command if it succeeded. Stops with an 126 | error message if it failed.

    127 | 128 |

    Examples

    129 |
    if (FALSE) sp_docker_network_create("sql-pet")
    130 |
    131 | 140 |
    141 | 142 | 143 |
    144 | 147 | 148 |
    149 |

    Site built with pkgdown 1.4.1.

    150 |
    151 | 152 |
    153 |
    154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | -------------------------------------------------------------------------------- /docs/reference/sp_docker_networks_tibble.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | List networks into a tibble — sp_docker_networks_tibble • sqlpetr 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
    60 |
    61 | 95 | 96 | 97 | 98 |
    99 | 100 |
    101 |
    102 | 107 | 108 |
    109 |

    Creates a tibble of networks using docker network

    110 |
    111 | 112 |
    sp_docker_networks_tibble()
    113 | 114 | 115 |

    Value

    116 | 117 |

    A tibble listing the networks

    118 | 119 |

    Examples

    120 |
    if (FALSE) { 121 | docker_networks <- sp_docker_networks_tibble() 122 | View(docker_networks) 123 | }
    124 |
    125 | 133 |
    134 | 135 | 136 |
    137 | 140 | 141 |
    142 |

    Site built with pkgdown 1.4.1.

    143 |
    144 | 145 |
    146 |
    147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | -------------------------------------------------------------------------------- /docs/reference/sp_docker_remove_container.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Forcibly remove a container — sp_docker_remove_container • sqlpetr 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 55 | 56 | 57 | 58 | 59 | 60 | 61 |
    62 |
    63 | 97 | 98 | 99 | 100 |
    101 | 102 |
    103 |
    104 | 109 | 110 |
    111 |

    Forcibly removes a Docker container. If it is running it will be 112 | forcibly terminated and removed. If it doesn't exist you won't get an error 113 | message. This is a blunt instrument!

    114 |
    115 | 116 |
    sp_docker_remove_container(docker_container)
    117 | 118 |

    Arguments

    119 | 120 | 121 | 122 | 123 | 125 | 126 |
    docker_container

    character: the name of the container to 124 | remove

    127 | 128 |

    Value

    129 | 130 |

    a numeric 0

    131 |

    Details

    132 | 133 |

    Warning: this function removes the container you asked it to remove!

    134 | 135 |

    Examples

    136 |
    if (FALSE) sp_docker_remove_container("sql-pet")
    137 |
    138 | 148 |
    149 | 150 | 151 |
    152 | 155 | 156 |
    157 |

    Site built with pkgdown 1.4.1.

    158 |
    159 | 160 |
    161 |
    162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | -------------------------------------------------------------------------------- /docs/reference/sp_docker_remove_image.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Forcibly remove an image — sp_docker_remove_image • sqlpetr 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 54 | 55 | 56 | 57 | 58 | 59 | 60 |
    61 |
    62 | 96 | 97 | 98 | 99 |
    100 | 101 |
    102 |
    103 | 108 | 109 |
    110 |

    Forcibly removes a Docker image. If it doesn't exist you won't 111 | get an error message. This is a blunt instrument!

    112 |
    113 | 114 |
    sp_docker_remove_image(docker_image)
    115 | 116 |

    Arguments

    117 | 118 | 119 | 120 | 121 | 122 | 123 |
    docker_image

    character: the name of the image to remove

    124 | 125 |

    Value

    126 | 127 |

    a numeric 0

    128 |

    Details

    129 | 130 |

    Warning: this function removes the image you asked it to remove!

    131 | 132 |

    Examples

    133 |
    if (FALSE) sp_docker_remove_image("docker.io/postgres:10")
    134 |
    135 | 145 |
    146 | 147 | 148 |
    149 | 152 | 153 |
    154 |

    Site built with pkgdown 1.4.1.

    155 |
    156 | 157 |
    158 |
    159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /docs/reference/sp_docker_start.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Start an existing container — sp_docker_start • sqlpetr 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
    60 |
    61 | 95 | 96 | 97 | 98 |
    99 | 100 |
    101 |
    102 | 107 | 108 |
    109 |

    Starts the container given by container_name.

    110 |
    111 | 112 |
    sp_docker_start(container_name)
    113 | 114 |

    Arguments

    115 | 116 | 117 | 118 | 119 | 120 | 121 |
    container_name

    character: container to start

    122 | 123 |

    Value

    124 | 125 |

    Result of Docker command if it succeeded. Stops with an 126 | error message if it failed.

    127 | 128 |

    Examples

    129 |
    if (FALSE) sp_docker_start("sql-pet")
    130 |
    131 | 140 |
    141 | 142 | 143 |
    144 | 147 | 148 |
    149 |

    Site built with pkgdown 1.4.1.

    150 |
    151 | 152 |
    153 |
    154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | -------------------------------------------------------------------------------- /docs/reference/sp_docker_stop.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Stop an existing container — sp_docker_stop • sqlpetr 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
    60 |
    61 | 95 | 96 | 97 | 98 |
    99 | 100 |
    101 |
    102 | 107 | 108 |
    109 |

    Stops the container given by container_name.

    110 |
    111 | 112 |
    sp_docker_stop(container_name)
    113 | 114 |

    Arguments

    115 | 116 | 117 | 118 | 119 | 120 | 121 |
    container_name

    character: container to stop

    122 | 123 |

    Value

    124 | 125 |

    Result of Docker command if it succeeded. Stops with an 126 | error message if it failed.

    127 | 128 |

    Examples

    129 |
    if (FALSE) sp_docker_stop("sql-pet")
    130 |
    131 | 140 |
    141 | 142 | 143 |
    144 | 147 | 148 |
    149 |

    Site built with pkgdown 1.4.1.

    150 |
    151 | 152 |
    153 |
    154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | -------------------------------------------------------------------------------- /docs/reference/sp_fetch_dvdrental_autodoc.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Fetch <code>dvdrental</code> autodoc — sp_fetch_dvdrental_autodoc • sqlpetr 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
    66 |
    67 | 101 | 102 | 103 | 104 |
    105 | 106 |
    107 |
    108 | 113 | 114 |
    115 |

    When sp_make_dvdrental_image builds the Docker image, it 116 | installs a utility called 117 | postgresql-autodoc. After restoring 118 | the dvdrental database, it runs the utilily and creates an HTML file with 119 | the database documentation on the image at 120 | /var/lib/postgresql/dvdrental.html. This function fetches that file to a 121 | file on the Docker host.

    122 |
    123 | 124 |
    sp_fetch_dvdrental_autodoc(container_name = "sql-pet", file_path)
    125 | 126 |

    Arguments

    127 | 128 | 129 | 130 | 131 | 133 | 134 | 135 | 136 | 139 | 140 |
    container_name

    character: The container name where the dvdrental 132 | database is running. The default is "sql-pet".

    file_path

    character: A valid file path to receive the HTML file. It 137 | should be an absolute path so you know where to find it, and the filename 138 | should end in .html so the browser can open it. There is no default.

    141 | 142 |

    Value

    143 | 144 |

    If successful: a character value of lenght 0. If unsuccessful, the 145 | function terminates with an error message.

    146 | 147 |
    148 | 156 |
    157 | 158 | 159 |
    160 | 163 | 164 |
    165 |

    Site built with pkgdown 1.4.1.

    166 |
    167 | 168 |
    169 |
    170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | -------------------------------------------------------------------------------- /docs/reference/sp_get_dbms_data_dictionary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Download a table from the dbms and create a data dictionary data frame — sp_get_dbms_data_dictionary • sqlpetr 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
    60 |
    61 | 95 | 96 | 97 | 98 |
    99 | 100 |
    101 |
    102 | 107 | 108 |
    109 |

    Download a table from the dbms and create a data dictionary data frame

    110 |
    111 | 112 |
    sp_get_dbms_data_dictionary(table_name, con = con)
    113 | 114 |

    Arguments

    115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 |
    table_name

    The name of a table to be processed.

    con

    A DBI connection object for obtaining the local copy to be processed

    126 | 127 |

    Value

    128 | 129 |

    a data frame table_dd

    130 | 131 |

    Examples

    132 |
    if (FALSE) all_meta <- sp_get_dbms_data_dictionary("rental")
    133 |
    134 | 143 |
    144 | 145 | 146 |
    147 | 150 | 151 |
    152 |

    Site built with pkgdown 1.4.1.

    153 |
    154 | 155 |
    156 |
    157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /docs/reference/sp_get_fivenumsum.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Calculate a 5 number summary (for all types of variables) — sp_get_fivenumsum • sqlpetr 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
    60 |
    61 | 95 | 96 | 97 | 98 |
    99 | 100 |
    101 |
    102 | 107 | 108 |
    109 |

    Calculate a 5 number summary (for all types of variables)

    110 |
    111 | 112 |
    sp_get_fivenumsum(var, character_truncate_length = 60)
    113 | 114 |

    Arguments

    115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 |
    var

    The variable to be summarized

    character_truncate_length

    the length of output character summaries (for )

    126 | 127 |

    Value

    128 | 129 |

    The min, max, median, and 25th and 75th percentiles

    130 | 131 |

    Examples

    132 |
    summary_vector <- sp_get_fivenumsum(mtcars$mpg)
    133 |
    134 | 143 |
    144 | 145 | 146 |
    147 | 150 | 151 |
    152 |

    Site built with pkgdown 1.4.1.

    153 |
    154 | 155 |
    156 |
    157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /docs/reference/sp_make_data_dictionary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Run sp_get_fivenumsum on all variables in a data frame — sp_make_data_dictionary • sqlpetr 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
    60 |
    61 | 95 | 96 | 97 | 98 |
    99 | 100 |
    101 |
    102 | 107 | 108 |
    109 |

    Run sp_get_fivenumsum on all variables in a data frame

    110 |
    111 | 112 |
    sp_make_data_dictionary(df, df_alias = NULL)
    113 | 114 |

    Arguments

    115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 |
    df

    data frame to be summarized

    df_alias

    name of the data frame to be appended

    126 | 127 |

    Value

    128 | 129 |

    a data frame

    130 | 131 |

    Examples

    132 |
    table_dd <- sp_make_data_dictionary(mtcars)
    133 |
    134 | 143 |
    144 | 145 | 146 |
    147 | 150 | 151 |
    152 |

    Site built with pkgdown 1.4.1.

    153 |
    154 | 155 |
    156 |
    157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /docs/reference/sp_make_dvdrental_image.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Make <code>dvdrental</code> Docker image — sp_make_dvdrental_image • sqlpetr 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 54 | 55 | 56 | 57 | 58 | 59 | 60 |
    61 |
    62 | 96 | 97 | 98 | 99 |
    100 | 101 |
    102 |
    103 | 108 | 109 |
    110 |

    Creates a Docker image with PostgreSQL and the dvdrental 111 | database

    112 |
    113 | 114 |
    sp_make_dvdrental_image(image_tag)
    115 | 116 |

    Arguments

    117 | 118 | 119 | 120 | 121 | 122 | 123 |
    image_tag

    character: a valid image tag (name) for the docker image

    124 | 125 |

    Value

    126 | 127 |

    Result of Docker command if it succeeded. Stops with an error message 128 | if it failed.

    129 |

    Details

    130 | 131 |

    See the vignette "Building the dvdrental Docker Image" for the 132 | details.

    133 | 134 |

    Examples

    135 |
    if (FALSE) { 136 | build_log <- sp_make_dvdrental_image("test-dvdrental:latest") 137 | sp_docker_images_tibble() 138 | }
    139 |
    140 | 150 |
    151 | 152 | 153 |
    154 | 157 | 158 |
    159 |

    Site built with pkgdown 1.4.1.

    160 |
    161 | 162 |
    163 |
    164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | -------------------------------------------------------------------------------- /docs/reference/sp_make_simple_pg.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Make simple PostgreSQL container — sp_make_simple_pg • sqlpetr 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 55 | 56 | 57 | 58 | 59 | 60 | 61 |
    62 |
    63 | 97 | 98 | 99 | 100 |
    101 | 102 |
    103 |
    104 | 109 | 110 |
    111 |

    Creates a container and runs the PostgreSQL 10 image 112 | (docker.io/postgres:10) in it. The image will be downloaded if it doesn't 113 | exist locally.

    114 |
    115 | 116 |
    sp_make_simple_pg(container_name, postgres_password = "postgres")
    117 | 118 |

    Arguments

    119 | 120 | 121 | 122 | 123 | 125 | 126 | 127 | 128 | 130 | 131 |
    container_name

    character: a valid container name for the 124 | container

    postgres_password

    character: superuser password. Default is 129 | "postgres".

    132 | 133 |

    Value

    134 | 135 |

    Result of Docker command if it succeeded. Stops with an 136 | error message if it failed.

    137 | 138 |

    Examples

    139 |
    if (FALSE) { 140 | run_log <- sp_make_simple_pg("livestock") 141 | sp_docker_images_tibble() 142 | sp_docker_containers_tibble() 143 | }
    144 |
    145 | 154 |
    155 | 156 | 157 |
    158 | 161 | 162 |
    163 |

    Site built with pkgdown 1.4.1.

    164 |
    165 | 166 |
    167 |
    168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | -------------------------------------------------------------------------------- /docs/reference/sp_pg_close_connection.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Notify observer and close connection — sp_pg_close_connection • sqlpetr 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 54 | 55 | 56 | 57 | 58 | 59 | 60 |
    61 |
    62 | 96 | 97 | 98 | 99 |
    100 | 101 |
    102 |
    103 | 108 | 109 |
    110 |

    Tells the connections tab observer that connection was closed 111 | and then closes it

    112 |
    113 | 114 |
    sp_pg_close_connection(connection)
    115 | 116 |

    Arguments

    117 | 118 | 119 | 120 | 121 | 122 | 123 |
    connection

    A valid open connection from sp_get_postgres_connection.

    124 | 125 |

    Value

    126 | 127 |

    not meaningful

    128 | 129 |
    130 | 138 |
    139 | 140 | 141 |
    142 | 145 | 146 |
    147 |

    Site built with pkgdown 1.4.1.

    148 |
    149 | 150 |
    151 |
    152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | -------------------------------------------------------------------------------- /docs/reference/sp_print_df.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Show (print) a data frame depending on appropriate output type — sp_print_df • sqlpetr 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
    60 |
    61 | 95 | 96 | 97 | 98 |
    99 | 100 |
    101 |
    102 | 107 | 108 |
    109 |

    Show (print) a data frame depending on appropriate output type

    110 |
    111 | 112 |
    sp_print_df(df)
    113 | 114 |

    Arguments

    115 | 116 | 117 | 118 | 119 | 120 | 121 |
    df

    the data frame to be shown

    122 | 123 |

    Value

    124 | 125 |

    either kable (in PDF) or datatable (in HTML) output

    126 | 127 |

    Examples

    128 |
    if (FALSE) sp_print_df(df)
    129 |
    130 | 139 |
    140 | 141 | 142 |
    143 | 146 | 147 |
    148 |

    Site built with pkgdown 1.4.1.

    149 |
    150 | 151 |
    152 |
    153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | -------------------------------------------------------------------------------- /docs/reference/sp_show_all_docker_containers.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Check that docker is running — sp_show_all_docker_containers • sqlpetr 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
    60 |
    61 | 95 | 96 | 97 | 98 |
    99 | 100 |
    101 |
    102 | 107 | 108 |
    109 |

    Check that docker is running

    110 |
    111 | 112 |
    sp_show_all_docker_containers()
    113 | 114 | 115 |

    Value

    116 | 117 |

    0

    118 | 119 |

    Examples

    120 |
    if (FALSE) sp_show_all_docker_containers()
    121 |
    122 | 130 |
    131 | 132 | 133 |
    134 | 137 | 138 |
    139 |

    Site built with pkgdown 1.4.1.

    140 |
    141 | 142 |
    143 |
    144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /inst/extdata/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM docker.io/postgres:10 2 | LABEL maintainer="M. Edward (Ed) Borasky " 3 | 4 | # Install apt packages 5 | RUN apt-get update \ 6 | && apt-get install -qqy --no-install-recommends \ 7 | postgresql-autodoc \ 8 | unzip \ 9 | && apt-get clean 10 | 11 | # download and extract the zip archive 12 | WORKDIR / 13 | ADD http://www.postgresqltutorial.com/wp-content/uploads/2017/10/dvdrental.zip / 14 | RUN unzip /dvdrental.zip 15 | 16 | # load the extract script into the "magic pocket" 17 | COPY restoredb.sh /docker-entrypoint-initdb.d/ 18 | -------------------------------------------------------------------------------- /inst/extdata/docker/restoredb.sh: -------------------------------------------------------------------------------- 1 | echo "creating the 'dvdrental' database" 2 | createdb dvdrental 3 | echo "restoring the database" 4 | pg_restore -U postgres -d dvdrental /dvdrental.tar 5 | echo "running postgresql-autodoc" 6 | cd /var/lib/postgresql 7 | postgresql_autodoc -d dvdrental -t html 8 | -------------------------------------------------------------------------------- /inst/icons/edit-sql.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smithjd/sqlpetr/f73cdbae569cb5a2c9f6231a513156da308e2192/inst/icons/edit-sql.png -------------------------------------------------------------------------------- /inst/icons/help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smithjd/sqlpetr/f73cdbae569cb5a2c9f6231a513156da308e2192/inst/icons/help.png -------------------------------------------------------------------------------- /inst/icons/postgresql.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smithjd/sqlpetr/f73cdbae569cb5a2c9f6231a513156da308e2192/inst/icons/postgresql.png -------------------------------------------------------------------------------- /inst/linux/arch_dependencies.bash: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | echo "Installing Linux dependencies" 4 | sudo pacman --sync --noconfirm --needed \ 5 | base \ 6 | base-devel \ 7 | docker \ 8 | gcc-fortran \ 9 | postgresql-libs \ 10 | r 11 | echo "Adding you to the 'docker' group" 12 | sudo usermod -aG docker ${USER} 13 | echo "Enabling and starting the Docker service" 14 | sudo systemctl enable --now docker.service 15 | echo "You will need to log out to the display manager prompt" 16 | echo "and log back in again to use the 'docker' command." 17 | -------------------------------------------------------------------------------- /inst/linux/fedora_dependencies.bash: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | echo "Installing Linux dependencies" 4 | echo "Installing Linux dependencies" 5 | sudo dnf install -y \ 6 | dnf-plugins-core \ 7 | libcurl-devel \ 8 | libxml2-devel \ 9 | openssl-devel \ 10 | postgresql-devel \ 11 | R 12 | sudo dnf config-manager --add-repo \ 13 | https://download.docker.com/linux/fedora/docker-ce.repo 14 | sudo dnf install -y \ 15 | docker-ce \ 16 | docker-ce-cli \ 17 | containerd.io 18 | echo "Adding you to the 'docker' group" 19 | sudo usermod -aG docker ${USER} 20 | echo "Enabling and starting the Docker service" 21 | sudo systemctl enable --now docker.service 22 | echo "You will need to log out to the display manager prompt" 23 | echo "and log back in again to use the 'docker' command." 24 | -------------------------------------------------------------------------------- /inst/linux/ubuntu_dependencies.bash: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | echo "Installing 'sqlpetr' prerequisites" 4 | echo "Installing Linux dependencies" 5 | sudo apt-get update && sudo apt-get install -qqy --no-install-recommends \ 6 | apt-transport-https \ 7 | ca-certificates \ 8 | curl \ 9 | gnupg-agent \ 10 | libcurl4-openssl-dev \ 11 | libpq-dev \ 12 | libssl-dev \ 13 | libxml2-dev \ 14 | r-base \ 15 | r-base-dev \ 16 | software-properties-common 17 | curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - 18 | sudo add-apt-repository \ 19 | "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ 20 | $(lsb_release -cs) \ 21 | stable" 22 | sudo apt-get update && sudo apt-get install -qqy --no-install-recommends \ 23 | docker-ce \ 24 | docker-ce-cli \ 25 | containerd.io 26 | echo "Adding you to the 'docker' group" 27 | sudo usermod -aG docker ${USER} 28 | echo "Enabling and starting the Docker service" 29 | sudo systemctl enable --now docker.service 30 | echo "You will need to log out to the display manager prompt" 31 | echo "and log back in again to use the 'docker' command." 32 | -------------------------------------------------------------------------------- /inst/rstudio/connections.dcf: -------------------------------------------------------------------------------- 1 | Name: sqlpetr 2 | -------------------------------------------------------------------------------- /inst/rstudio/connections/sqlpetr.R: -------------------------------------------------------------------------------- 1 | library(sqlpetr) 2 | # defaults for the "sql-pet" container with "dvdrental" database 3 | # change the parameter values for your own database configuration 4 | connection <- sp_get_postgres_connection( 5 | user = "postgres", 6 | password = "postgres", 7 | dbname = "dvdrental", 8 | host = "localhost", 9 | port = 5439, 10 | seconds_to_test = 30, 11 | connection_tab = TRUE 12 | ) 13 | -------------------------------------------------------------------------------- /inst/sql_code/schemata.sql: -------------------------------------------------------------------------------- 1 | SELECT schema_name FROM information_schema.schemata 2 | WHERE left(schema_name, 3) != 'pg_' 3 | AND schema_name != 'information_schema'; -------------------------------------------------------------------------------- /man/sp_check_that_docker_is_up.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sp_check_that_docker_is_up.R 3 | \name{sp_check_that_docker_is_up} 4 | \alias{sp_check_that_docker_is_up} 5 | \title{Check that docker is running} 6 | \usage{ 7 | sp_check_that_docker_is_up() 8 | } 9 | \value{ 10 | 0 11 | } 12 | \description{ 13 | Check that docker is running 14 | } 15 | \examples{ 16 | \dontrun{sp_check_that_docker_is_up()} 17 | } 18 | -------------------------------------------------------------------------------- /man/sp_color_markdown_text.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sp_color_markdown_text.R 3 | \name{sp_color_markdown_text} 4 | \alias{sp_color_markdown_text} 5 | \title{Color subsequent text in a specified color} 6 | \usage{ 7 | sp_color_markdown_text(x, color) 8 | } 9 | \arguments{ 10 | \item{x}{a string} 11 | 12 | \item{color}{color to apply} 13 | } 14 | \value{ 15 | colored string 16 | } 17 | \description{ 18 | Color subsequent text in a specified color 19 | } 20 | \examples{ 21 | # sp_color_markdown_text('Cover inline tables in future section','red') 22 | } 23 | -------------------------------------------------------------------------------- /man/sp_docker_build.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sp_docker_functions.R 3 | \name{sp_docker_build} 4 | \alias{sp_docker_build} 5 | \title{Build a Docker image} 6 | \usage{ 7 | sp_docker_build(build_options, build_context_path) 8 | } 9 | \arguments{ 10 | \item{build_options}{character: the build options. There are many; do 11 | \verb{docker build --help} at a command prompt to see them. You will need at least 12 | the \code{--tag} option to give the built image a tag (name).} 13 | 14 | \item{build_context_path}{character: the build context path} 15 | } 16 | \value{ 17 | Result of Docker command if it succeeded. Stops with an error message 18 | if it failed. 19 | } 20 | \description{ 21 | Creates a Docker image 22 | } 23 | -------------------------------------------------------------------------------- /man/sp_docker_containers_tibble.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sp_docker_functions.R 3 | \name{sp_docker_containers_tibble} 4 | \alias{sp_docker_containers_tibble} 5 | \title{List containers into a tibble} 6 | \usage{ 7 | sp_docker_containers_tibble(list_all = FALSE) 8 | } 9 | \arguments{ 10 | \item{list_all}{logical: list all containers if \code{TRUE}, just 11 | \emph{running} containers if \code{FALSE}. Default is \code{FALSE}.} 12 | } 13 | \value{ 14 | A tibble listing the containers. If there are none, 15 | returns an empty (0x0) tibble. 16 | } 17 | \description{ 18 | Creates a tibble of containers using \verb{docker ps} 19 | } 20 | \examples{ 21 | \dontrun{ 22 | sp_docker_containers_tibble(list_all = FALSE) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /man/sp_docker_images_tibble.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sp_docker_functions.R 3 | \name{sp_docker_images_tibble} 4 | \alias{sp_docker_images_tibble} 5 | \title{List images into a tibble} 6 | \usage{ 7 | sp_docker_images_tibble(list_all = FALSE) 8 | } 9 | \arguments{ 10 | \item{list_all}{logical: list all images if \code{TRUE}, just 11 | \emph{tagged} images if \code{FALSE}. Default is \code{FALSE}.} 12 | } 13 | \value{ 14 | A tibble listing the images 15 | } 16 | \description{ 17 | Creates a tibble of images using \verb{docker images} 18 | } 19 | \examples{ 20 | \dontrun{ 21 | sp_docker_images_tibble(list_all = FALSE) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /man/sp_docker_network_create.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sp_docker_functions.R 3 | \name{sp_docker_network_create} 4 | \alias{sp_docker_network_create} 5 | \title{Create a Docker network} 6 | \usage{ 7 | sp_docker_network_create(network_name = "sql-pet") 8 | } 9 | \arguments{ 10 | \item{network_name}{character: network to create. The default is \code{sql-pet}.} 11 | } 12 | \value{ 13 | Result of Docker command if it succeeded. Stops with an 14 | error message if it failed. 15 | } 16 | \description{ 17 | Creates a Docker network with name \code{network_name}. 18 | } 19 | \examples{ 20 | \dontrun{sp_docker_network_create("sql-pet")} 21 | } 22 | -------------------------------------------------------------------------------- /man/sp_docker_networks_tibble.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sp_docker_functions.R 3 | \name{sp_docker_networks_tibble} 4 | \alias{sp_docker_networks_tibble} 5 | \title{List networks into a tibble} 6 | \usage{ 7 | sp_docker_networks_tibble() 8 | } 9 | \value{ 10 | A tibble listing the networks 11 | } 12 | \description{ 13 | Creates a tibble of networks using \verb{docker network} 14 | } 15 | \examples{ 16 | \dontrun{ 17 | docker_networks <- sp_docker_networks_tibble() 18 | View(docker_networks) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /man/sp_docker_remove_container.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sp_docker_functions.R 3 | \name{sp_docker_remove_container} 4 | \alias{sp_docker_remove_container} 5 | \title{Forcibly remove a container} 6 | \usage{ 7 | sp_docker_remove_container(docker_container) 8 | } 9 | \arguments{ 10 | \item{docker_container}{character: the name of the container to 11 | remove} 12 | } 13 | \value{ 14 | a numeric \code{0} 15 | } 16 | \description{ 17 | Forcibly removes a Docker container. If it is running it will be 18 | forcibly terminated and removed. If it doesn't exist you won't get an error 19 | message. This is a blunt instrument! 20 | } 21 | \details{ 22 | Warning: this function removes the container you asked it to remove! 23 | } 24 | \examples{ 25 | \dontrun{sp_docker_remove_container("sql-pet")} 26 | } 27 | -------------------------------------------------------------------------------- /man/sp_docker_remove_image.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sp_docker_functions.R 3 | \name{sp_docker_remove_image} 4 | \alias{sp_docker_remove_image} 5 | \title{Forcibly remove an image} 6 | \usage{ 7 | sp_docker_remove_image(docker_image) 8 | } 9 | \arguments{ 10 | \item{docker_image}{character: the name of the image to remove} 11 | } 12 | \value{ 13 | a numeric \code{0} 14 | } 15 | \description{ 16 | Forcibly removes a Docker image. If it doesn't exist you won't 17 | get an error message. This is a blunt instrument! 18 | } 19 | \details{ 20 | Warning: this function removes the image you asked it to remove! 21 | } 22 | \examples{ 23 | \dontrun{sp_docker_remove_image("docker.io/postgres:10")} 24 | } 25 | -------------------------------------------------------------------------------- /man/sp_docker_run.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sp_docker_functions.R 3 | \name{sp_docker_run} 4 | \alias{sp_docker_run} 5 | \title{Run a Docker image} 6 | \usage{ 7 | sp_docker_run(image_tag, options = "", command = "", args = "") 8 | } 9 | \arguments{ 10 | \item{image_tag}{character: a valid image tag (name) for the docker image. If 11 | it doesn't exist locally, \verb{docker run} will try to download it. If the 12 | download then fails, the function will stop with an error message. 13 | 14 | Note that the full syntax of an image tag is \verb{/:}. For 15 | example, the PostgreSQL 10 image we use is \code{docker.io/postgres:10}.} 16 | 17 | \item{options}{character: the options to use when running the image. Default 18 | is the empty string. You will usually need at least the \code{--name} option to 19 | give the container a name.} 20 | 21 | \item{command}{character: the command to run after the container boots up. 22 | Default is an empty string, which uses the startup command defined in the 23 | image.} 24 | 25 | \item{args}{character: the arguments for the command. Default is an empty 26 | string.} 27 | } 28 | \value{ 29 | Result of Docker command if it succeeded. Stops with an error message 30 | if it failed. 31 | } 32 | \description{ 33 | Creates a container and runs an image in it. 34 | } 35 | \details{ 36 | Do \verb{docker run --help} in a command prompt to see all the options, 37 | of which there are many. 38 | } 39 | \examples{ 40 | \dontrun{ 41 | print(sp_docker_run("hello-world")) 42 | sp_docker_images_tibble() 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /man/sp_docker_start.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sp_docker_functions.R 3 | \name{sp_docker_start} 4 | \alias{sp_docker_start} 5 | \title{Start an existing container} 6 | \usage{ 7 | sp_docker_start(container_name) 8 | } 9 | \arguments{ 10 | \item{container_name}{character: container to start} 11 | } 12 | \value{ 13 | Result of Docker command if it succeeded. Stops with an 14 | error message if it failed. 15 | } 16 | \description{ 17 | Starts the container given by \code{container_name}. 18 | } 19 | \examples{ 20 | \dontrun{sp_docker_start("sql-pet")} 21 | } 22 | -------------------------------------------------------------------------------- /man/sp_docker_stop.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sp_docker_functions.R 3 | \name{sp_docker_stop} 4 | \alias{sp_docker_stop} 5 | \title{Stop an existing container} 6 | \usage{ 7 | sp_docker_stop(container_name) 8 | } 9 | \arguments{ 10 | \item{container_name}{character: container to stop} 11 | } 12 | \value{ 13 | Result of Docker command if it succeeded. Stops with an 14 | error message if it failed. 15 | } 16 | \description{ 17 | Stops the container given by \code{container_name}. 18 | } 19 | \examples{ 20 | \dontrun{sp_docker_stop("sql-pet")} 21 | } 22 | -------------------------------------------------------------------------------- /man/sp_fetch_dvdrental_autodoc.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sp_postgresql_functions.R 3 | \name{sp_fetch_dvdrental_autodoc} 4 | \alias{sp_fetch_dvdrental_autodoc} 5 | \title{Fetch \code{dvdrental} autodoc} 6 | \usage{ 7 | sp_fetch_dvdrental_autodoc(container_name = "sql-pet", file_path) 8 | } 9 | \arguments{ 10 | \item{container_name}{character: The container name where the \code{dvdrental} 11 | database is running. The default is "sql-pet".} 12 | 13 | \item{file_path}{character: A valid file path to receive the HTML file. It 14 | should be an absolute path so you know where to find it, and the filename 15 | should end in \code{.html} so the browser can open it. There is no default.} 16 | } 17 | \value{ 18 | If successful: a character value of lenght 0. If unsuccessful, the 19 | function terminates with an error message. 20 | } 21 | \description{ 22 | When \code{sp_make_dvdrental_image} builds the Docker image, it 23 | installs a utility called 24 | \href{https://github.com/cbbrowne/autodoc}{\code{postgresql-autodoc}}. After restoring 25 | the \code{dvdrental} database, it runs the utilily and creates an HTML file with 26 | the database documentation on the image at 27 | \verb{/var/lib/postgresql/dvdrental.html}. This function fetches that file to a 28 | file on the Docker host. 29 | } 30 | -------------------------------------------------------------------------------- /man/sp_get_dbms_data_dictionary.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sp_get_dbms_data_dictionary.R 3 | \name{sp_get_dbms_data_dictionary} 4 | \alias{sp_get_dbms_data_dictionary} 5 | \title{Download a table from the dbms and create a data dictionary data frame} 6 | \usage{ 7 | sp_get_dbms_data_dictionary(table_name, con = con) 8 | } 9 | \arguments{ 10 | \item{table_name}{The name of a table to be processed.} 11 | 12 | \item{con}{A DBI connection object for obtaining the local copy to be processed} 13 | } 14 | \value{ 15 | a data frame \code{table_dd} 16 | } 17 | \description{ 18 | Download a table from the dbms and create a data dictionary data frame 19 | } 20 | \examples{ 21 | \dontrun{all_meta <- sp_get_dbms_data_dictionary("rental")} 22 | } 23 | -------------------------------------------------------------------------------- /man/sp_get_fivenumsum.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sp_get_fivenumsum.R 3 | \name{sp_get_fivenumsum} 4 | \alias{sp_get_fivenumsum} 5 | \title{Calculate a 5 number summary (for all types of variables)} 6 | \usage{ 7 | sp_get_fivenumsum(var, character_truncate_length = 60) 8 | } 9 | \arguments{ 10 | \item{var}{The variable to be summarized} 11 | 12 | \item{character_truncate_length}{the length of output character summaries (for )} 13 | } 14 | \value{ 15 | The min, max, median, and 25th and 75th percentiles 16 | } 17 | \description{ 18 | Calculate a 5 number summary (for all types of variables) 19 | } 20 | \examples{ 21 | summary_vector <- sp_get_fivenumsum(mtcars$mpg) 22 | } 23 | -------------------------------------------------------------------------------- /man/sp_get_postgres_connection.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sp_postgresql_functions.R 3 | \name{sp_get_postgres_connection} 4 | \alias{sp_get_postgres_connection} 5 | \title{Connect to a PostgreSQL database} 6 | \usage{ 7 | sp_get_postgres_connection( 8 | user = "postgres", 9 | password = "postgres", 10 | dbname = "dvdrental", 11 | host = "localhost", 12 | port = 5439, 13 | seconds_to_test = 30, 14 | connection_tab = FALSE 15 | ) 16 | } 17 | \arguments{ 18 | \item{user}{character: Username for connecting to the database. The user 19 | must exist and be authorized to connect. The default is "postgres".} 20 | 21 | \item{password}{character: Password that corresponds to the username. The 22 | password must be correct for the user. The default is "postgres".} 23 | 24 | \item{dbname}{character: The name of the database within the database server. 25 | The database must exist, and the user must be authorized to access it. 26 | The default is "dvdrental".} 27 | 28 | \item{host}{character: The IP address or host where postgreSQL is located, 29 | defaults to "localhost"} 30 | 31 | \item{port}{integer: The port on the host that PostgreSQL listens on, defaults 32 | to \emph{5439}. Note that this is \emph{not} the PostgreSQL default port, 5432! Why? If 33 | PostgreSQL is running on the host or in another container, it probably has 34 | claimed port 5432, since that's its default, and our container won't work! 35 | So we need to use a different port for \emph{our} PostgreSQL container.} 36 | 37 | \item{seconds_to_test}{integer: The number of iterations to try while waiting 38 | for PostgreSQL service to be ready. The function sleeps one second between 39 | connection attempts, so a value of 10 would require approximately 10 seconds. 40 | The default is 30.} 41 | 42 | \item{connection_tab}{logical: \code{sp_get_postgres_connection} can open a 43 | tab in the RStudio connections pane. \code{connection_tab = FALSE} is 44 | the default - call with \code{connection_tab = TRUE} to open the tab.} 45 | } 46 | \value{ 47 | If successful: a connection object, which is an S4 object 48 | that inherits from DBIConnection, used to communicate with the 49 | database engine. If unsuccessful, the function terminates with an 50 | error message. 51 | } 52 | \description{ 53 | Attempts to connect to a PostgreSQL database. If the connection 54 | fails, it will retry a user-specified number of times. 55 | } 56 | \examples{ 57 | \dontrun{con <- sp_get_postgres_connection( 58 | user = "postgres", 59 | password = "postgres", 60 | dbname = "postgres" 61 | )} 62 | \dontrun{ 63 | build_log <- sp_make_dvdrental_image("test-dvdrental:latest") 64 | sp_docker_images_tibble() 65 | sp_pg_docker_run( 66 | container_name = "test-dvdrental", 67 | image_tag = "test-dvdrental:latest", 68 | postgres_password = "postgres" 69 | ) 70 | sp_docker_containers_tibble() 71 | connection <- sp_get_postgres_connection( 72 | user = "postgres", 73 | password = "postgres", 74 | dbname = "dvdrental", 75 | host = "localhost", 76 | port = 5439, 77 | seconds_to_test = 30, 78 | connection_tab = TRUE 79 | ) 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /man/sp_make_data_dictionary.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sp_make_data_dictionary.R 3 | \name{sp_make_data_dictionary} 4 | \alias{sp_make_data_dictionary} 5 | \title{Run sp_get_fivenumsum on all variables in a data frame} 6 | \usage{ 7 | sp_make_data_dictionary(df, df_alias = NULL) 8 | } 9 | \arguments{ 10 | \item{df}{data frame to be summarized} 11 | 12 | \item{df_alias}{name of the data frame to be appended} 13 | } 14 | \value{ 15 | a data frame 16 | } 17 | \description{ 18 | Run sp_get_fivenumsum on all variables in a data frame 19 | } 20 | \examples{ 21 | table_dd <- sp_make_data_dictionary(mtcars) 22 | } 23 | -------------------------------------------------------------------------------- /man/sp_make_dvdrental_image.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sp_docker_functions.R 3 | \name{sp_make_dvdrental_image} 4 | \alias{sp_make_dvdrental_image} 5 | \title{Make \code{dvdrental} Docker image} 6 | \usage{ 7 | sp_make_dvdrental_image(image_tag) 8 | } 9 | \arguments{ 10 | \item{image_tag}{character: a valid image tag (name) for the docker image} 11 | } 12 | \value{ 13 | Result of Docker command if it succeeded. Stops with an error message 14 | if it failed. 15 | } 16 | \description{ 17 | Creates a Docker image with PostgreSQL and the \code{dvdrental} 18 | database 19 | } 20 | \details{ 21 | See the vignette "Building the \code{dvdrental} Docker Image" for the 22 | details. 23 | } 24 | \examples{ 25 | \dontrun{ 26 | build_log <- sp_make_dvdrental_image("test-dvdrental:latest") 27 | sp_docker_images_tibble() 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /man/sp_make_simple_pg.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sp_docker_functions.R 3 | \name{sp_make_simple_pg} 4 | \alias{sp_make_simple_pg} 5 | \title{Make simple PostgreSQL container} 6 | \usage{ 7 | sp_make_simple_pg(container_name, postgres_password = "postgres") 8 | } 9 | \arguments{ 10 | \item{container_name}{character: a valid container name for the 11 | container} 12 | 13 | \item{postgres_password}{character: superuser password. Default is 14 | "postgres".} 15 | } 16 | \value{ 17 | Result of Docker command if it succeeded. Stops with an 18 | error message if it failed. 19 | } 20 | \description{ 21 | Creates a container and runs the PostgreSQL 10 image 22 | (\code{docker.io/postgres:10}) in it. The image will be downloaded if it doesn't 23 | exist locally. 24 | } 25 | \examples{ 26 | \dontrun{ 27 | run_log <- sp_make_simple_pg("livestock") 28 | sp_docker_images_tibble() 29 | sp_docker_containers_tibble() 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /man/sp_pg_catalog.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sp_postgresql_functions.R 3 | \name{sp_pg_catalog} 4 | \alias{sp_pg_catalog} 5 | \title{Fetch a PostgreSQL database catalog} 6 | \usage{ 7 | sp_pg_catalog(connection) 8 | } 9 | \arguments{ 10 | \item{connection}{A valid open \code{DBI} connection to a PostgreSQL database.} 11 | } 12 | \value{ 13 | A data frame with the contents of the database catalog. The columns 14 | are \code{schemas}, \code{name}, and \code{type}, where \code{type} is "matview" (materialized 15 | view), "view" or "table". 16 | } 17 | \description{ 18 | PostgreSQL stores much of its metadata in system catalogs that 19 | are accessible to a connected user. This function takes a connection and 20 | returns the database catalog as a data frame. 21 | } 22 | \examples{ 23 | \dontrun{ 24 | library(sqlpetr) 25 | library(dplyr) 26 | connection <- sp_get_postgres_connection( 27 | user = "postgres", 28 | password = "postgres", 29 | dbname = "dvdrental" 30 | ) 31 | print(sp_pg_catalog(connection)) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /man/sp_pg_close_connection.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sp_postgresql_functions.R 3 | \name{sp_pg_close_connection} 4 | \alias{sp_pg_close_connection} 5 | \title{Notify observer and close connection} 6 | \usage{ 7 | sp_pg_close_connection(connection) 8 | } 9 | \arguments{ 10 | \item{connection}{A valid open connection from \code{sp_get_postgres_connection}.} 11 | } 12 | \value{ 13 | not meaningful 14 | } 15 | \description{ 16 | Tells the connections tab observer that connection was closed 17 | and then closes it 18 | } 19 | -------------------------------------------------------------------------------- /man/sp_pg_docker_run.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sp_docker_functions.R 3 | \name{sp_pg_docker_run} 4 | \alias{sp_pg_docker_run} 5 | \title{Run a PostgreSQL Docker image in a container} 6 | \usage{ 7 | sp_pg_docker_run( 8 | container_name, 9 | image_tag = "docker.io/postgres:10", 10 | postgres_password = "postgres", 11 | postgres_port = 5439, 12 | docker_network = "sql-pet" 13 | ) 14 | } 15 | \arguments{ 16 | \item{container_name}{character: a valid container name for the container} 17 | 18 | \item{image_tag}{character: a valid image tag (name) for the docker image to 19 | run. Default is the base PostgreSQL 10 image, \code{docker.io/postgres:10}.} 20 | 21 | \item{postgres_password}{character: the \code{postgres} database superuser 22 | password. Default is "postgres".} 23 | 24 | \item{postgres_port}{integer: the PostgreSQL port. The default is \emph{5439}. 25 | Note that the default is 5439 instead of the usual PostgreSQL default, 5432. 26 | Why? If PostgreSQL is running on the host or in another container, it probably 27 | has claimed port 5432, since that's its default, and our container won't work! 28 | So we need to use a different port for \emph{our} PostgreSQL container.} 29 | 30 | \item{docker_network}{character: the Docker network to host the container. 31 | The default is "sql-pet". The network will be created if it does not exist.} 32 | } 33 | \value{ 34 | If the Docker command fails, \code{sp_pg_docker_run} will stop with an 35 | error message. If the Docker command succeeds, \code{sp_pg_docker_run} will wait 36 | 30 seconds for the database to come up with \code{sp_get_postgres_connection}. 37 | If that fails, \code{sp_get_postgres_connection} will stop with an error message. 38 | If it succeeds, \code{sp_pg_docker_run} will close the connection and return the 39 | \emph{Docker} result. 40 | } 41 | \description{ 42 | Creates a container and runs an image in it. The image 43 | must be based on the \code{docker.io/postgres:10} image. It will run in the 44 | background (\code{--detach}) and the container PostgreSQL port will be 45 | published to \code{localhost}. 46 | } 47 | \examples{ 48 | \dontrun{ 49 | build_log <- sp_make_dvdrental_image("test-dvdrental:latest") 50 | sp_docker_images_tibble() 51 | sp_pg_docker_run( 52 | container_name = "test-dvdrental", 53 | image_tag = "test-dvdrental:latest", 54 | postgres_password = "postgres" 55 | ) 56 | sp_docker_containers_tibble() 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /man/sp_print_df.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sp_print_df.R 3 | \name{sp_print_df} 4 | \alias{sp_print_df} 5 | \title{Show (print) a data frame depending on appropriate output type} 6 | \usage{ 7 | sp_print_df(df) 8 | } 9 | \arguments{ 10 | \item{df}{the data frame to be shown} 11 | } 12 | \value{ 13 | either kable (in PDF) or datatable (in HTML) output 14 | } 15 | \description{ 16 | Show (print) a data frame depending on appropriate output type 17 | } 18 | \examples{ 19 | \dontrun{sp_print_df(df)} 20 | } 21 | -------------------------------------------------------------------------------- /man/sp_show_all_docker_containers.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sp_show_all_docker_containers.R 3 | \name{sp_show_all_docker_containers} 4 | \alias{sp_show_all_docker_containers} 5 | \title{Check that docker is running} 6 | \usage{ 7 | sp_show_all_docker_containers() 8 | } 9 | \value{ 10 | 0 11 | } 12 | \description{ 13 | Check that docker is running 14 | } 15 | \examples{ 16 | \dontrun{sp_show_all_docker_containers()} 17 | } 18 | -------------------------------------------------------------------------------- /sqlpetr.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: Yes 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: knitr 13 | LaTeX: XeLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | PackageRoxygenize: rd,collate,namespace,vignette 22 | 23 | QuitChildProcessesOnExit: Yes 24 | -------------------------------------------------------------------------------- /tests/test_pkg.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "1. Building function documentation ..." 3 | R -e "library(devtools); devtools::load_all(); devtools::document()" 4 | echo "2. Building package documentation ..." 5 | R -e "library(pkgdown); pkgdown::build_site()" 6 | echo "3. Checking package, including unit tests ..." 7 | R -e "library(devtools); devtools::load_all(); devtools::check()" 8 | -------------------------------------------------------------------------------- /tests/testthat/test_dvdrental_image.R: -------------------------------------------------------------------------------- 1 | 2 | context("Build, run and test the 'DVD Rental' container") 3 | 4 | test_that("dvd_rental_runs", { 5 | 6 | # define constants 7 | image_tag <- "test-dvdrental:latest" 8 | container_name <- "test-dvdrental" 9 | postgres_user = "postgres" 10 | postgres_password = "charlie_h0rse" 11 | table_list <- c( 12 | "actor_info", 13 | "customer_list", 14 | "film_list", 15 | "nicer_but_slower_film_list", 16 | "sales_by_film_category", 17 | "staff", 18 | "sales_by_store", 19 | "staff_list", 20 | "category", 21 | "film_category", 22 | "country", 23 | "actor", 24 | "language", 25 | "inventory", 26 | "payment", 27 | "rental", 28 | "city", 29 | "store", 30 | "film", 31 | "address", 32 | "film_actor", 33 | "customer" 34 | ) 35 | 36 | # force remove container and image 37 | sp_docker_remove_container(container_name) 38 | sp_docker_remove_image(image_tag) 39 | 40 | # build the image 41 | sp_make_dvdrental_image(image_tag) 42 | 43 | # run the container 44 | sp_pg_docker_run(container_name, 45 | image_tag = image_tag, 46 | postgres_password = postgres_password 47 | ) 48 | 49 | # connect 50 | conn <- sp_get_postgres_connection( 51 | user = postgres_user, 52 | password = postgres_password, 53 | dbname = "dvdrental", 54 | seconds_to_test = 30 55 | ) 56 | 57 | # list the tables 58 | tables <- DBI::dbListTables(conn) 59 | expect_equal(tables, table_list) 60 | 61 | # shut down and cleanup 62 | DBI::dbDisconnect(conn) 63 | sp_docker_remove_container(container_name) 64 | sp_docker_remove_image(image_tag) 65 | }) 66 | -------------------------------------------------------------------------------- /tests/testthat/test_sp_get_postgres_connection.R: -------------------------------------------------------------------------------- 1 | 2 | context("Connecting to a PostgreSQL instance") 3 | 4 | EXPECTED_ERROR_MESSAGE = "There is no connection" 5 | 6 | test_that("Expects error message when unable to connect", { 7 | conn <- sp_get_postgres_connection( 8 | user = "unknown_user", 9 | password = "some_password", 10 | dbname = "unknown_database", 11 | seconds_to_test = 3 12 | ) 13 | expect_equal(conn, EXPECTED_ERROR_MESSAGE) 14 | }) 15 | 16 | test_that("Expects negative 'seconds_to_test' is ignored", { 17 | conn <- sp_get_postgres_connection( 18 | user = "unknown_user", 19 | password = "some_password", 20 | dbname = "unknown_database", 21 | seconds_to_test = -1 22 | ) 23 | expect_equal(conn, EXPECTED_ERROR_MESSAGE) 24 | }) 25 | 26 | test_that("Handles 0 seconds_to_test", { 27 | conn <- sp_get_postgres_connection( 28 | user = "unknown_user", 29 | password = "some_password", 30 | dbname = "unknown_database", 31 | seconds_to_test = 0 32 | ) 33 | expect_equal(conn, EXPECTED_ERROR_MESSAGE) 34 | }) 35 | --------------------------------------------------------------------------------