1- # ' Export to Excel
1+ # ' Export to Tabular
22# '
33# ' @param core_project_numbers A character vector of NIH Core Project Numbers
44# ' @param token The token required for authentication with the GitHub API
55# ' @param service_account_json A character string containing the path to a JSON file containing a Google service account
66# ' @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
78# '
89# ' @importFrom openxlsx createWorkbook addWorksheet writeData saveWorkbook
10+ # ' @importFrom readr write_csv
911# ' @importFrom rlang .data
1012# ' @export
1113# '
1416# ' test_projects <-c("OT2OD030545")
1517# ' }
1618# '
17- export_excel <- function (core_project_numbers , token = gitcreds :: gitcreds_get()$ password , service_account_json = ' cfde-access-keyfile.json' , dir ) {
19+ export_tabular <- function (core_project_numbers , token = gitcreds :: gitcreds_get()$ password , service_account_json = ' cfde-access-keyfile.json' , dir , csv = FALSE ) {
1820
1921 # # Create Excel Workbook
2022 wb <- createWorkbook()
@@ -23,6 +25,9 @@ export_excel <- function(core_project_numbers, token = gitcreds::gitcreds_get()$
2325 addWorksheet(wb , " project_info" )
2426 proj_info <- get_core_project_info(core_project_numbers )
2527 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+ }
2631
2732 # # Add Assosciated Publications
2833 addWorksheet(wb , " pub_info" )
@@ -31,16 +36,25 @@ export_excel <- function(core_project_numbers, token = gitcreds::gitcreds_get()$
3136 pull(' pmid' )
3237 pub_info <- icite(pmids )
3338 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+ }
3442
3543 # # Add GitHub
3644 addWorksheet(wb , " github_info" )
3745 github_info <- get_github_by_topic_graphql(core_project_numbers , token = token )
3846 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+ }
3950
4051 # # Add Google Analytics
4152 addWorksheet(wb , " ga_info" )
4253 ga_info <- get_ga_basic(core_project_numbers = core_project_numbers , service_account_json = service_account_json )
4354 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+ }
4458
4559 # # Save Workbook
4660 saveWorkbook(wb , file.path(dir , paste0(" programets_" , Sys.Date(), " .xlsx" , sep = " " )))
0 commit comments