1+ # ' Export to Tabular
2+ # '
3+ # ' @param core_project_numbers A character vector of NIH Core Project Numbers
4+ # ' @param token The token required for authentication with the GitHub API
5+ # ' @param service_account_json A character string containing the path to a JSON file containing a Google service account
6+ # ' @param dir A character string containing the path to directory where the Excel file will be written
7+ # ' @param csv A logical indicating whether to write a CSV file
8+ # '
9+ # ' @importFrom openxlsx createWorkbook addWorksheet writeData saveWorkbook
10+ # ' @importFrom readr write_csv
11+ # ' @importFrom rlang .data
12+ # ' @export
13+ # '
14+ # ' @examples
15+ # ' \dontrun{
16+ # ' test_projects <-c("OT2OD030545")
17+ # ' }
18+ # '
19+ export_tabular <- function (core_project_numbers , token = gitcreds :: gitcreds_get()$ password , service_account_json = ' cfde-access-keyfile.json' , dir , csv = FALSE ) {
20+
21+ # # Create Excel Workbook
22+ wb <- createWorkbook()
23+
24+ # # Add NIH Project Info
25+ addWorksheet(wb , " project_info" )
26+ proj_info <- get_core_project_info(core_project_numbers )
27+ writeData(wb = wb , sheet = " project_info" , x = proj_info , na.string = " " )
28+ if (csv ) {
29+ write_csv(proj_info , file.path(dir , paste0(" programets_proj_info_" , Sys.Date(), " .csv" , sep = " " )))
30+ }
31+
32+ # # Add Assosciated Publications
33+ addWorksheet(wb , " pub_info" )
34+ pmids <- proj_info | >
35+ filter(.data $ found_publication ) | >
36+ pull(' pmid' )
37+ pub_info <- icite(pmids )
38+ writeData(wb = wb , sheet = " pub_info" , x = pub_info , na.string = " " )
39+ if (csv ) {
40+ write_csv(pub_info , file.path(dir , paste0(" programets_pub_info_" , Sys.Date(), " .csv" , sep = " " )))
41+ }
42+
43+ # # Add GitHub
44+ addWorksheet(wb , " github_info" )
45+ github_info <- get_github_by_topic_graphql(core_project_numbers , token = token )
46+ writeData(wb = wb , sheet = " github_info" , x = github_info , na.string = " " )
47+ if (csv ) {
48+ write_csv(github_info , file.path(dir , paste0(" programets_github_info_" , Sys.Date(), " .csv" , sep = " " )))
49+ }
50+
51+ # # Add Google Analytics
52+ addWorksheet(wb , " ga_info" )
53+ ga_info <- get_ga_basic(core_project_numbers = core_project_numbers , service_account_json = service_account_json )
54+ writeData(wb = wb , sheet = " ga_info" , x = ga_info , na.string = " " )
55+ if (csv ) {
56+ write_csv(ga_info , file.path(dir , paste0(" programets_ga_info_" , Sys.Date(), " .csv" , sep = " " )))
57+ }
58+
59+ # # Save Workbook
60+ saveWorkbook(wb , file.path(dir , paste0(" programets_" , Sys.Date(), " .xlsx" , sep = " " )))
61+ }
0 commit comments