### Get YAML file path with system.file() Source: https://rstudio.github.io/pointblank/reference/yaml_informant_incorporate.html Retrieves the path to the example YAML file 'informant-small_table.yml' included in the pointblank package. ```r yml_file_path <- system.file( "yaml", "informant-small_table.yml", package = "pointblank" ) ``` -------------------------------- ### Install development version of pointblank from GitHub Source: https://rstudio.github.io/pointblank/ Installs the development version of pointblank from GitHub using pak. Requires the pak package; uncomment the first line to install it if needed. ```r # install.packages("pak") pak::pak("rstudio/pointblank") ``` -------------------------------- ### Install pointblank from CRAN Source: https://rstudio.github.io/pointblank/ Installs the stable release of pointblank from CRAN. ```r install.packages("pointblank") ``` -------------------------------- ### Example: glimpse game_revenue Source: https://rstudio.github.io/pointblank/reference/game_revenue.html This example uses dplyr::glimpse to display the structure and first values of the game_revenue dataset. The output shows 2,000 rows and 11 columns with sample values for each variable. ```r # Here is a glimpse at the data # available in `game_revenue` dplyr::glimpse(game_revenue) #> Rows: 2,000 #> Columns: 11 #> $ player_id "ECPANOIXLZHF896", "ECPANOIXLZHF896", "ECPANOIXLZHF89…" #> $ session_id "ECPANOIXLZHF896-eol2j8bs", "ECPANOIXLZHF896-eol2j8bs…" #> $ session_start 2015-01-01 01:31:03, 2015-01-01 01:31:03, 2015-01-01… #> $ time 2015-01-01 01:31:27, 2015-01-01 01:36:57, 2015-01-01… #> $ item_type "iap", "iap", "iap", "ad", "ad", "ad", "ad", "ad", "a…" #> $ item_name "offer2", "gems3", "gold7", "ad_20sec", "ad_5sec", "a…" #> $ item_revenue 8.991, 22.491, 107.991, 0.760, 0.030, 0.070, 0.080, 1… #> $ session_duration 16.3, 16.3, 16.3, 16.3, 35.2, 35.2, 35.2, 35.2, 35.2,… #> $ start_day 2015-01-01, 2015-01-01, 2015-01-01, 2015-01-01, 2015… #> $ acquisition "google", "google", "google", "google", "google", "go…" #> $ country "Germany", "Germany", "Germany", "Germany", "Germany"… ``` -------------------------------- ### from_github() examples for generating GitHub URLs Source: https://rstudio.github.io/pointblank/reference/from_github.html These commented examples illustrate various ways to use from_github() to generate URLs for files in the pointblank repository, including from the default branch, with a subdirectory, in combination with file_tbl() and create_agent(), from a release tag, a specific commit, and an open pull request. ```r # A valid URL to a data file in GitHub can be # obtained from the HEAD of the default branch # from_github( # file = "inst/data_files/small_table.csv", # repo = "rstudio/pointblank" # ) # The path to the file location can be supplied # fully or partially to `subdir` # from_github( # file = "small_table.csv", # repo = "rstudio/pointblank", # subdir = "inst/data_files" # ) # We can use the first call in combination with # `file_tbl()` and `create_agent()`; this # supplies a table-prep formula that gets # a CSV file from the GitHub repository for the # pointblank package # agent <- # create_agent( # tbl = ~ file_tbl( # file = from_github( # file = "inst/data_files/small_table.csv", # repo = "rstudio/pointblank" # ), # col_types = "TDdcddlc" # ) # ) |> # col_vals_gt(a, 0) |> # interrogate() # The `from_github()` helper function is # pretty powerful and can get at lots of # different files in a repository # A data file from GitHub can be obtained from # a commit at release time # from_github( # file = "inst/extdata/small_table.csv", # repo = "rstudio/pointblank@v0.2.1" # ) # A file may also be obtained from a repo at the # point in time of a specific commit (partial or # full SHA-1 hash for the commit can be used) # from_github( # file = "data-raw/small_table.csv", # repo = "rstudio/pointblank@e04a71" # ) # A file may also be obtained from an # *open* pull request # from_github( # file = "data-raw/small_table.csv", # repo = "rstudio/pointblank#248" # ) ``` -------------------------------- ### Example: Create SQLite version of small_table Source: https://rstudio.github.io/pointblank/reference/small_table_sqlite.html Example usage of small_table_sqlite() to create an SQLite version of the small_table dataset. The code is commented out in the source. ```r # Use `small_table_sqlite()` to # create an SQLite version of the # `small_table` table # # small_table_sqlite <- small_table_sqlite() ``` -------------------------------- ### Datetime as prefix with position = 'start' Source: https://rstudio.github.io/pointblank/reference/affix_datetime.html Uses the 'position' argument set to 'start' to place the datetime before the filename. ```R affix_datetime( filename = "pb_file", position = "start" ) ``` ```output ## [1] "2022-04-01_00-32-53_pb_file" ``` -------------------------------- ### affix_date() with position = "start" Source: https://rstudio.github.io/pointblank/reference/affix_date.html Uses the date as a prefix by setting position = "start". The output shows the date prepended to the filename. ```r affix_date( filename = "pb_file", position = "start" ) ``` ```output ## [1] "2022-04-01_pb_file" ``` -------------------------------- ### Create sample tibble for conjointly examples Source: https://rstudio.github.io/pointblank/reference/conjointly.html Creates a simple tibble with three numeric columns (a, b, c) used across all examples on this page. The output shows the resulting tibble. ```r tbl <- dplyr::tibble( a = c(5, 2, 6), b = c(3, 4, 6), c = c(9, 8, 7) ) tbl #> # A tibble: 3 x 3 #> a b c #> #> 1 5 3 9 #> 2 2 4 8 #> 3 6 6 7 ``` -------------------------------- ### Using test_col_vals_not_in_set() to get a logical value Source: https://rstudio.github.io/pointblank/reference/col_vals_not_in_set.html Test form returns a single logical value. The example shows the output TRUE for the given validation. ```R small_table |> test_col_vals_not_in_set( columns = f, set = c("lows", "mids", "highs") ) #> [1] TRUE ``` -------------------------------- ### Create table store with tbl_store() and two table-prep formulas Source: https://rstudio.github.io/pointblank/reference/tbl_store.html Defines store_1 with two table-prep formulas: tbl_duckdb (an in-memory DuckDB table from pointblank::small_table) and sml_table_high (a filtered version of tbl_duckdb). Use this to set up a table store for later materialization. ```R store_1 <- tbl_store( tbl_duckdb ~ db_tbl( pointblank::small_table, dbname = ":memory:", dbtype = "duckdb" ), sml_table_high ~ db_tbl( pointblank::small_table, dbname = ":memory:", dbtype = "duckdb" ) |> dplyr::filter(f == "high") ) ``` -------------------------------- ### Use test_col_is_numeric() to get a logical value Source: https://rstudio.github.io/pointblank/reference/col_is_numeric.html Returns a single logical value indicating whether the validation passes. The example shows TRUE for the 'd' column. ```r small_table |> test_col_is_numeric(columns = d) #> [1] TRUE ``` -------------------------------- ### Use table store with create_agent() and tbl_source() Source: https://rstudio.github.io/pointblank/reference/db_tbl.html Shows how to use the table store in create_agent() by passing a table-prep formula that calls tbl_source() with the store name 'tbls'. ```R agent <- create_agent( tbl = ~ tbl_source( tbl = "small_table_duck", store = tbls ) ) ``` -------------------------------- ### Access fraction of failed test units from x-list Source: https://rstudio.github.io/pointblank/reference/create_agent.html After obtaining an x-list, access the f_failed element to get the fraction of test units that failed. The example shows a value of 0.15385. ```r xl_step_4$f_failed ``` ```output #> [1] 0.15385 ``` -------------------------------- ### Example: create agent, add validation steps, interrogate, then remove a step Source: https://rstudio.github.io/pointblank/reference/remove_steps.html This example creates an agent with the small_table object, adds validation steps (col_exists and col_vals_regex), interrogates, then removes the second validation step using remove_steps(i = 2) and interrogates again. Note that removing steps also removes stored data extracts. ```r # Create an agent that has the # `small_table` object as the # target table, add a few # validation steps, and then use # `interrogate()` agent_1 <- create_agent( tbl = small_table, tbl_name = "small_table", label = "An example." ) |> col_exists(columns = date) |> col_vals_regex( columns = b, pattern = "[0-9]-[a-z]{3}-[0-9]" ) |> interrogate() # The second validation step has # been determined to be unneeded and # is to be removed; this can be done # by using `remove_steps()` with the # agent object agent_2 <- agent_1 |> remove_steps(i = 2) |> interrogate() ``` -------------------------------- ### Get path to CSV file in pointblank package Source: https://rstudio.github.io/pointblank/reference/file_tbl.html Uses system.file() to obtain the path to a CSV file (small_table.csv) included in the pointblank package. This path is used in subsequent file_tbl() examples. ```R csv_path <- system.file( "data_files", "small_table.csv", package = "pointblank" ) ``` -------------------------------- ### Get agent x-list for a specific step with get_agent_x_list() Source: https://rstudio.github.io/pointblank/reference/create_agent.html Use get_agent_x_list() to obtain an x-list for a specific validation step. The example stores the x-list for step 4 in a variable named xl_step_4. ```r xl_step_4 <- agent |> get_agent_x_list(i = 4) ``` -------------------------------- ### Create an agent with a table from the store using $ notation Source: https://rstudio.github.io/pointblank/reference/tbl_store.html Creates an agent `agent_1` by passing `store_3$small_table_duck` to the `tbl` argument of `create_agent()`. ```R agent_1 <- create_agent( tbl = store_3$small_table_duck ) ``` -------------------------------- ### Get status counts with cdisc_status_counts() Source: https://rstudio.github.io/pointblank/articles/cdisc-conformance.html Breaks down rules by status: pass, fail, error, not_applicable, and not_supported. The example output shows 7 fail, 12 not_applicable, and 407 pass. ```R cdisc_status_counts(result) ``` ```output ## statuses ## fail not_applicable pass ## 7 12 407 ``` -------------------------------- ### Example: Create informant with snip_lowest() Source: https://rstudio.github.io/pointblank/reference/snip_lowest.html Builds an informant object, adds a snippet using `snip_lowest()` to get the lowest value from column `a`, and incorporates it into the info text. The order of `info_columns()` and `info_snippet()` calls does not matter. ```r informant <- create_informant( tbl = ~ small_table, tbl_name = "small_table", label = "An example." ) |> info_columns( columns = a, `Lowest Value` = "Lowest value is {lowest_a}." ) |> info_snippet( snippet_name = "lowest_a", fn = snip_lowest(column = "a") ) |> incorporate() ``` -------------------------------- ### Get row-level findings with cdisc_findings_df() Source: https://rstudio.github.io/pointblank/articles/cdisc-conformance.html Flattens per-row findings into a tidy data frame. The example selects rule_id, dataset, row, usubjid, checked_column, and checked_value. The row column uses 1-based indexing. ```R cdisc_findings_df(result) |> dplyr::select(rule_id, dataset, row, usubjid, checked_column, checked_value) ``` ```output ## rule_id dataset row usubjid checked_column checked_value ## 1 SDTM-007 DM 3 STUDY01-003 SEX INVALID ## 2 SDTM-011 DM 2 STUDY01-002 RFSTDTC not-a-date ``` -------------------------------- ### Create a tbl_store with table-prep formulas Source: https://rstudio.github.io/pointblank/reference/tbl_source.html Creates a tbl_store object with two table-prep formulas: one using db_tbl() for a DuckDB table and one referencing pointblank::small_table. ```R store <- tbl_store( small_table_duck ~ db_tbl( table = small_table, dbname = ":memory:", dbtype = "duckdb" ), sml_table ~ pointblank::small_table ) ``` -------------------------------- ### Use table store with create_informant() and tbl_source() Source: https://rstudio.github.io/pointblank/reference/db_tbl.html Shows how to use the table store in create_informant() by passing a table-prep formula that calls tbl_source() with the store name 'tbls'. ```R informant <- create_informant( tbl = ~ tbl_source( tbl = "small_high_duck", store = tbls ) ) ``` -------------------------------- ### Check missing columns with tidyselect helper Source: https://rstudio.github.io/pointblank/reference/has_columns.html Checks for columns starting with 'h' and for 'a' plus columns starting with 'h'. Both return FALSE because no columns start with 'h'. ```r small_table |> has_columns(columns = starts_with("h")) small_table |> has_columns(columns = c(a, starts_with("h"))) ``` ```r ## [1] FALSE ## [1] FALSE ``` -------------------------------- ### Create informant with table-prep formula and incorporate() Source: https://rstudio.github.io/pointblank/articles/INFO-2.html Creates an informant using tbl = ~ target_table (a formula that re-obtains the table each time) and calls incorporate() to finalize the report. The output shows the header with 13 rows and 8 columns. ```R informant_tt <- create_informant( tbl = ~ target_table, tbl_name = "target_table", label = "Example No. 3" ) |> incorporate() informant_tt ``` -------------------------------- ### Create email object from agent with email_create() Source: https://rstudio.github.io/pointblank/reference/email_create.html Builds a pointblank agent, runs validation steps, interrogates, and creates an email object with email_create(). Printing the resulting email_object displays the HTML email in the Viewer. ```R email_object <- create_agent( tbl = small_table, tbl_name = "small_table", label = "An example.", actions = al ) |> col_vals_gt(a, value = 1) |> col_vals_lt(a, value = 7) |> interrogate() |> email_create() email_object ``` -------------------------------- ### Create agent with file_tbl() from GitHub and interrogate Source: https://rstudio.github.io/pointblank/reference/file_tbl.html Uses from_github() to read a CSV from the pointblank GitHub repository. The agent is created with a table-prep formula, a table name, and a label, then adds a col_vals_gt() step and interrogates. The downloaded file is stored in a system temp directory by default. ```R agent <- create_agent( tbl = ~ file_tbl( file = from_github( file = "inst/data_files/small_table.csv", repo = "rstudio/pointblank" ), col_types = "TDdcddlc" ), tbl_name = "small_table", label = "`file_tbl()` example.", ) |> col_vals_gt(columns = a, value = 0) |> interrogate() ``` ```R agent ``` -------------------------------- ### Print the tbl_store object to see summary Source: https://rstudio.github.io/pointblank/reference/tbl_store.html Printing `store_3` displays a summary of the table-prep formulas, showing each name and its formula. ```R store_3 ``` -------------------------------- ### Create sample tibble for col_exists() examples Source: https://rstudio.github.io/pointblank/reference/col_exists.html Defines the tibble `tbl` with columns `a` and `b` used in all examples on this page. The output shows the resulting tibble. ```r tbl <- dplyr::tibble( a = c(5, 7, 6, 5, 8, 7), b = c(7, 1, 0, 0, 0, 3) ) tbl #> # A tibble: 6 x 2 #> a b #> #> 1 5 7 #> 2 7 1 #> 3 6 0 #> 4 5 0 #> 5 8 0 #> 6 7 3 ``` -------------------------------- ### Define a tbl_store object with table-prep formulas Source: https://rstudio.github.io/pointblank/reference/tbl_store.html Creates a `tbl_store` object named `store_3` containing four table-prep formulas: `small_table_duck` (DuckDB in-memory), an unnamed Postgres table `rna`, `all_revenue` (from a GitHub file), and `sml_table` (pointblank::small_table). ```R store_3 <- tbl_store( small_table_duck ~ db_tbl( table = small_table, dbname = ":memory:", dbtype = "duckdb" ), ~ db_tbl( table = "rna", dbname = "pfmegrnargs", dbtype = "postgres", host = "hh-pgsql-public.ebi.ac.uk", port = 5432, user = I("reader"), password = I("NWDMCE5xdipIjRrp") ), all_revenue ~ db_tbl( table = file_tbl( file = from_github( file = "sj_all_revenue_large.rds", repo = "rich-iannone/intendo", subdir = "data-large" ) ), dbname = ":memory:", dbtype = "duckdb" ), sml_table ~ pointblank::small_table ) ``` -------------------------------- ### Template for db_tbl() with environment variables Source: https://rstudio.github.io/pointblank/reference/db_tbl.html Shows the required inputs for db_tbl() when using environment variables for credentials. Placeholders like and should be replaced with actual values. ```r example_db_tbl <- db_tbl( table = "", dbtype = "", dbname = "", host = "", port = "", user = "", password = "" ) ``` -------------------------------- ### Create summary statistics table with tt_time_slice() and tt_summary_stats() Source: https://rstudio.github.io/pointblank/reference/get_tt_param.html Builds a summary statistics table for the first quarter of the game_revenue dataset using tt_time_slice() with slice_point = 0.25 and tt_summary_stats(). The output shows a tibble with columns .param., item_revenue, and session_duration. ```r stats_tbl <- game_revenue |> tt_time_slice(slice_point = 0.25) |> tt_summary_stats() stats_tbl #> # A tibble: 9 x 3 #> .param. item_revenue session_duration #> #> 1 min 0.02 5.1 #> 2 p05 0.03 11 #> 3 q_1 0.08 17.2 #> 4 med 0.28 28.3 #> 5 q_3 1.37 32 #> 6 p95 40.0 37.1 #> 7 max 143. 41 #> 8 iqr 1.28 14.8 #> 9 range 143. 35.9 ``` -------------------------------- ### Create tbl_2 with dplyr::tibble() Source: https://rstudio.github.io/pointblank/reference/create_multiagent.html Creates the second example table used in the multiagent example. The table has columns a and b, with b containing the first six letters of the alphabet. ```r tbl_2 <- dplyr::tibble( a = c(5, 7, 6, 5, 8, 7), b = LETTERS[1:6] ) tbl_2 #> # A tibble: 6 x 2 #> a b #> #> 1 5 A #> 2 7 B #> 3 6 C #> 4 5 D #> 5 8 E #> 6 7 F ``` -------------------------------- ### Create sample tibble for col_vals_ge examples Source: https://rstudio.github.io/pointblank/reference/col_vals_ge.html Creates a tibble with three numeric columns (a, b, c) and three character columns (d, e, f) used in all examples on this page. ```R tbl <- dplyr::tibble( a = c(5, 5, 5, 5, 5, 5), b = c(1, 1, 1, 2, 2, 2), c = c(1, 1, 1, 2, 3, 4), d = LETTERS[a], e = LETTERS[b], f = LETTERS[c] ) tbl #> # A tibble: 6 x 6 #> a b c d e f #> #> 1 5 1 1 E A A #> 2 5 1 1 E A A #> 3 5 1 1 E A A #> 4 5 2 2 E B B #> 5 5 2 3 E B C #> 6 5 2 4 E B D ``` -------------------------------- ### Create agent_1 with validation steps Source: https://rstudio.github.io/pointblank/reference/get_multiagent_report.html Creates the first agent with eight validation steps and interrogates small_table. Uses create_agent() with label and actions, then pipes validation functions and interrogate(). ```r agent_1 <- create_agent( tbl = small_table, label = "An example.", actions = al ) |> col_vals_gt( columns = date_time, value = vars(date), na_pass = TRUE ) |> col_vals_gt( columns = b, value = vars(g), na_pass = TRUE ) |> rows_distinct() |> col_vals_equal( columns = d, value = vars(d), na_pass = TRUE ) |> col_vals_between( columns = c, left = vars(a), right = vars(d) ) |> col_vals_not_between( columns = c, left = 10, right = 20, na_pass = TRUE ) |> rows_distinct(columns = d, e, f) |> col_is_integer(columns = a) |> interrogate() ``` -------------------------------- ### Create sample tibble for col_vals_not_null examples Source: https://rstudio.github.io/pointblank/reference/col_vals_not_null.html Defines the tibble `tbl` used in all examples on this page. It has columns `a`, `b`, `c`, and `d`, with some NA values in `c` and `d`. The output shows the tibble structure. ```r tbl <- dplyr::tibble( a = c( 5, 7, 6, 5, 8), b = c( 7, 1, 0, 0, 0), c = c(NA, NA, NA, NA, NA), d = c(35, 23, NA, NA, NA) ) tbl #> # A tibble: 5 x 4 #> a b c d #> #> 1 5 7 NA 35 #> 2 7 1 NA 23 #> 3 6 0 NA NA #> 4 5 0 NA NA #> 5 8 0 NA NA ``` -------------------------------- ### Create an agent with create_agent() Source: https://rstudio.github.io/pointblank/reference/create_agent.html Creates a pointblank agent object using the small_table dataset, assigns a table name and label, and sets the action levels as the default for all validation steps. ```r agent <- create_agent( tbl = pointblank::small_table, tbl_name = "small_table", label = "`create_agent()` example.", actions = al ) ``` -------------------------------- ### A: Using an agent with col_vals_increasing() and interrogate() Source: https://rstudio.github.io/pointblank/reference/col_vals_increasing.html Creates a validation agent on game_revenue, applies col_vals_increasing() to session_start with allow_stationary = TRUE, and interrogates. The validation report is shown in the Viewer. ```r agent <- create_agent(tbl = game_revenue) |> col_vals_increasing( columns = session_start, allow_stationary = TRUE ) |> interrogate() ``` -------------------------------- ### Create sample tibble for col_vals_gt examples Source: https://rstudio.github.io/pointblank/reference/col_vals_gt.html Defines the tibble `tbl` with numeric columns `a`, `b`, `c` and character columns `d`, `e`, `f`. Used as the data for all validation examples on this page. ```r tbl <- dplyr::tibble( a = c(5, 5, 5, 5, 5, 5), b = c(1, 1, 1, 2, 2, 2), c = c(1, 1, 1, 2, 3, 4), d = LETTERS[a], e = LETTERS[b], f = LETTERS[c] ) tbl #> # A tibble: 6 x 6 #> a b c d e f #> #> 1 5 1 1 E A A #> 2 5 1 1 E A A #> 3 5 1 1 E A A #> 4 5 2 2 E B B #> 5 5 2 3 E B C #> 6 5 2 4 E B D ``` -------------------------------- ### R statement for col_vals_not_in_set() validation step Source: https://rstudio.github.io/pointblank/reference/col_vals_not_in_set.html Example of a complex col_vals_not_in_set() call in R, using preconditions, segments, actions, label, and active arguments. This is the R representation that corresponds to the YAML example below. ```R agent |> col_vals_not_in_set( columns = a, set = c(1, 2, 3, 4), preconditions = \(x) x |> dplyr::filter(a < 10), segments = b ~ c("group_1", "group_2"), actions = action_levels(warn = 0.1, error = 0.2), label = "The `col_vals_not_in_set()` step.", active = FALSE ) ``` -------------------------------- ### Define a tbl_store with table-prep formulas Source: https://rstudio.github.io/pointblank/reference/tbl_get.html Creates a tbl_store object named 'store' containing three table-prep formulas: a DuckDB table, a PostgreSQL table, and a local data frame. The PostgreSQL connection uses public credentials. ```r store <- tbl_store( small_table_duck ~ db_tbl( table = small_table, dbname = ":memory:", dbtype = "duckdb" ), ~ db_tbl( table = "rna", dbname = "pfmegrnargs", dbtype = "postgres", host = "hh-pgsql-public.ebi.ac.uk", port = 5432, user = I("reader"), password = I("NWDMCE5xdipIjRrp") ), sml_table ~ pointblank::small_table ) ```