Last active
August 14, 2018 14:38
-
-
Save boshek/3c2a0ec63db4856b3043fd5292c2301c to your computer and use it in GitHub Desktop.
A script to extract the column names for most tidyhydat functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
# Functions --------------------------------------------------------------- | |
eval_funcs <- function(x){ | |
cat(x,"\n") | |
if(grepl("hy_", x)){ | |
return(names(eval(parse(text = paste0(x,"(hydat_path = hy_test_db())"))))) | |
} | |
if(grepl("realtime_",x)){ | |
return(names(eval(parse(text = paste0(x,"('08MF005')"))))) | |
} | |
} | |
# Generate a vector of function names ------------------------------------- | |
## Grab from the NAMESPACE file | |
funcs <- str_subset(readLines("NAMESPACE"), "hy_|realtime_") %>% | |
str_replace("export\\(", "") %>% | |
str_replace("\\)","") | |
## Filter out the data exported objects | |
funcs <- funcs[!funcs %in% c(data(package = "tidyhydat")[["results"]][,3])] | |
## Filter out specific functions that aren't appropriate here | |
funcs <- funcs[!funcs %in% c("hy_default_db","hy_downloaded_db", | |
"hy_plot","hy_src_disconnect", "hy_src", | |
"hy_test_db","hy_set_default_db","realtime_add_local_datetime", | |
"realtime_daily_mean")] | |
# Iterate over functions and output the column headings ------------------- | |
devtools::load_all() | |
func_column_names <- map(funcs,eval_funcs) %>% | |
setNames(funcs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment