修订版 | b2bd2262d7b340292a1d2380b949f2ddcb67b59a (tree) |
---|---|
时间 | 2025-01-07 03:48:34 |
作者 | Lorenzo Isella <lorenzo.isella@gmai...> |
Commiter | Lorenzo Isella |
A script showcasing the pointblank package.
@@ -0,0 +1,54 @@ | ||
1 | +rm(list=ls()) | |
2 | + | |
3 | +library(tidyverse) | |
4 | +library(pointblank) | |
5 | +# Example data | |
6 | + | |
7 | +data <- data.frame( | |
8 | + id = 1:5, | |
9 | + name = c("Alice", "Bob", NA, "Diana", "Eve"), | |
10 | + score = c(85, 90, 78, NA, 92), | |
11 | + date = as.Date(c("2023-01-01", "2023-02-01", "2023-03-01", "2023-04-01", "2023-05-01")) | |
12 | +) | |
13 | + | |
14 | +# Combine multiple validations | |
15 | +agent <- | |
16 | + create_agent(tbl = data) %>% | |
17 | + col_vals_not_null(columns = vars(id, name, date)) %>% | |
18 | + col_vals_between(columns = vars(score), left = 0, right = 100) %>% | |
19 | + col_is_character(columns = vars(name)) %>% | |
20 | + col_is_numeric(columns = vars(score)) %>% | |
21 | + col_is_date(columns = vars(date)) %>% | |
22 | + interrogate() | |
23 | + | |
24 | +# Generate a validation report | |
25 | +agent | |
26 | + | |
27 | + | |
28 | + | |
29 | +# Create an informant and annotate the dataset | |
30 | + | |
31 | + | |
32 | +informant <- | |
33 | + create_informant(tbl = data, tbl_name = "example_dataset") %>% | |
34 | + info_columns( | |
35 | + info = list( | |
36 | + id = "Unique identifier for each row.", | |
37 | + name = "Name of the individual.", | |
38 | + score = "Score achieved by the individual (0-100).", | |
39 | + date = "Date of the recorded observation." | |
40 | + ) | |
41 | + ) %>% | |
42 | + info_section( | |
43 | + section_name = "Overview", | |
44 | + info = "This dataset contains information about individuals, their scores, and the associated dates." | |
45 | + ) %>% | |
46 | + incorporate() | |
47 | + | |
48 | +# Generate and view the report | |
49 | +informant | |
50 | + | |
51 | + | |
52 | + | |
53 | + | |
54 | +print("So far so good") |