Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using for loop #489

Closed
ZimSci opened this issue Sep 11, 2023 · 1 comment
Closed

Using for loop #489

ZimSci opened this issue Sep 11, 2023 · 1 comment

Comments

@ZimSci
Copy link

ZimSci commented Sep 11, 2023

I have a folder with 89 tables/files and I am trying to interrogate those tables in pointblank. Is it possible to use a for loop to create an agent and then interrogate all the files at once? Please advise what the best way would be (if any) so that I dont have to create an agent for all the 89 tables. Thank you.

@yjunechoe
Copy link
Collaborator

yjunechoe commented Nov 2, 2023

Good question. Firstly, I would read the tables into R and save them as a named list of dataframes. So something like:

tbl_list <- list(
  x = data.frame(a = "A"),
  y = data.frame(a = TRUE),
  z = data.frame(a = 1)
)

Then I would write a function that accepts a name from that list to grab the corresponding dataframe and run some set of validations on it:

apply_validations <- function(tbl_name) {
  tbl_list[[tbl_name]] %>% 
    create_agent(tbl_name = tbl_name) %>% 
    col_is_character("a") %>% 
    # Write more validation steps here!
    interrogate()
}

Applying this function to each data frame can be a single call to lapply(). This produces another list, where each element is the interrogate()-ed agent for each data frame.

agent_list <- lapply(names(tbl_list), apply_validations)
agent_reports <- lapply(agent_list, get_agent_report)

So then something like agent_reports[[1]] will give you the agent report for the first data frame.

Once you have a list of agents, you could go even further and stick them all inside a single html div and render that div, to view all reports at once.

do.call(htmltools::div, agent_reports) %>% 
  print(browse = TRUE)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants