From ba81c9501ceb916bee3b762269b62d4bd427ade8 Mon Sep 17 00:00:00 2001 From: chainsawriot Date: Thu, 24 Feb 2022 16:37:47 +0100 Subject: [PATCH 1/3] Decouple chapter order from file naming, ref #31 --- _bookdown.yml | 28 +++++++++++++++++++++++++--- figures/sort_chapters.R | 8 ++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 figures/sort_chapters.R diff --git a/_bookdown.yml b/_bookdown.yml index 35c1ea7..ed8279a 100644 --- a/_bookdown.yml +++ b/_bookdown.yml @@ -1,5 +1,27 @@ -book_filename: "2021_apis_for_social_scientists_a_collaborative_review" -delete_merged_file: true +book_filename: 2021_apis_for_social_scientists_a_collaborative_review +delete_merged_file: yes language: ui: - chapter_name: "Chapter " \ No newline at end of file + chapter_name: 'Chapter ' +rmd_files: +- index.Rmd +- 01-introduction.Rmd +- 02-Best_practices.Rmd +- 03-Ckan_api.Rmd +- 04-Crowdtangle_api.Rmd +- 05-Facebook_ads_library_api.Rmd +- 06-Genderize_api.Rmd +- 07-Github_api.Rmd +- 08-Google_news_api.Rmd +- 09-Google_nlp_api.Rmd +- 10-Google_places_api.Rmd +- 11-Google_speech.Rmd +- 12-Google_translation_api.Rmd +- 13-Googletrends_api.Rmd +- 14-Instagram_basic_display_api.Rmd +- 15-Instagram_graph_api.Rmd +- 16-Mediacloud_api.Rmd +- 17-Twitter_api.Rmd +- 18-Wiki_api.Rmd +- 19-Youtube_api.Rmd +- 99-References_Appendix.rmd diff --git a/figures/sort_chapters.R b/figures/sort_chapters.R new file mode 100644 index 0000000..de1a46d --- /dev/null +++ b/figures/sort_chapters.R @@ -0,0 +1,8 @@ +yaml_content <- read_yaml(here::here("_bookdown.yml")) +all_rmds <- fs::path_file(fs::dir_ls(here::here(), regexp = "^.+\\.[rR]md$")) +index_index <- which(all_rmds == "index.Rmd") +intro_index <- which(grepl("introduction", all_rmds)) +bp_index <- which(grepl("Best_practices", all_rmds)) +rmd_files <- all_rmds[c(index_index, intro_index, bp_index, setdiff(seq_along(all_rmds), c(index_index, intro_index, bp_index)))] +yaml_content$rmd_files <- rmd_files +write_yaml(yaml_content, here::here("_bookdown.yml")) From a48879424e0392718354a5698bd44dd86595d0a7 Mon Sep 17 00:00:00 2001 From: chainsawriot Date: Thu, 24 Feb 2022 16:57:10 +0100 Subject: [PATCH 2/3] Rename all chapters with the prefix `Chapter`, ref #31 Rename using emacs's Wdired mode --- ...ractices.Rmd => Chapter_Best_practices.Rmd | 0 03-Ckan_api.Rmd => Chapter_Ckan_api.Rmd | 0 ...gle_api.Rmd => Chapter_Crowdtangle_api.Rmd | 0 ...md => Chapter_Facebook_ads_library_api.Rmd | 0 ...erize_api.Rmd => Chapter_Genderize_api.Rmd | 0 07-Github_api.Rmd => Chapter_Github_api.Rmd | 0 ...ews_api.Rmd => Chapter_Google_news_api.Rmd | 0 ..._nlp_api.Rmd => Chapter_Google_nlp_api.Rmd | 0 ...s_api.Rmd => Chapter_Google_places_api.Rmd | 0 ...le_speech.Rmd => Chapter_Google_speech.Rmd | 0 ....Rmd => Chapter_Google_translation_api.Rmd | 0 ...ds_api.Rmd => Chapter_Googletrends_api.Rmd | 0 ...=> Chapter_Instagram_basic_display_api.Rmd | 0 ...api.Rmd => Chapter_Instagram_graph_api.Rmd | 0 ...troduction.Rmd => Chapter_Introduction.Rmd | 0 ...loud_api.Rmd => Chapter_Mediacloud_api.Rmd | 0 ...dix.rmd => Chapter_References_Appendix.rmd | 0 17-Twitter_api.Rmd => Chapter_Twitter_api.Rmd | 0 18-Wiki_api.Rmd => Chapter_Wiki_api.Rmd | 0 19-Youtube_api.Rmd => Chapter_Youtube_api.Rmd | 0 _bookdown.yml | 40 +++++++++---------- figures/sort_chapters.R | 5 ++- 22 files changed, 23 insertions(+), 22 deletions(-) rename 02-Best_practices.Rmd => Chapter_Best_practices.Rmd (100%) rename 03-Ckan_api.Rmd => Chapter_Ckan_api.Rmd (100%) rename 04-Crowdtangle_api.Rmd => Chapter_Crowdtangle_api.Rmd (100%) rename 05-Facebook_ads_library_api.Rmd => Chapter_Facebook_ads_library_api.Rmd (100%) rename 06-Genderize_api.Rmd => Chapter_Genderize_api.Rmd (100%) rename 07-Github_api.Rmd => Chapter_Github_api.Rmd (100%) rename 08-Google_news_api.Rmd => Chapter_Google_news_api.Rmd (100%) rename 09-Google_nlp_api.Rmd => Chapter_Google_nlp_api.Rmd (100%) rename 10-Google_places_api.Rmd => Chapter_Google_places_api.Rmd (100%) rename 11-Google_speech.Rmd => Chapter_Google_speech.Rmd (100%) rename 12-Google_translation_api.Rmd => Chapter_Google_translation_api.Rmd (100%) rename 13-Googletrends_api.Rmd => Chapter_Googletrends_api.Rmd (100%) rename 14-Instagram_basic_display_api.Rmd => Chapter_Instagram_basic_display_api.Rmd (100%) rename 15-Instagram_graph_api.Rmd => Chapter_Instagram_graph_api.Rmd (100%) rename 01-introduction.Rmd => Chapter_Introduction.Rmd (100%) rename 16-Mediacloud_api.Rmd => Chapter_Mediacloud_api.Rmd (100%) rename 99-References_Appendix.rmd => Chapter_References_Appendix.rmd (100%) rename 17-Twitter_api.Rmd => Chapter_Twitter_api.Rmd (100%) rename 18-Wiki_api.Rmd => Chapter_Wiki_api.Rmd (100%) rename 19-Youtube_api.Rmd => Chapter_Youtube_api.Rmd (100%) diff --git a/02-Best_practices.Rmd b/Chapter_Best_practices.Rmd similarity index 100% rename from 02-Best_practices.Rmd rename to Chapter_Best_practices.Rmd diff --git a/03-Ckan_api.Rmd b/Chapter_Ckan_api.Rmd similarity index 100% rename from 03-Ckan_api.Rmd rename to Chapter_Ckan_api.Rmd diff --git a/04-Crowdtangle_api.Rmd b/Chapter_Crowdtangle_api.Rmd similarity index 100% rename from 04-Crowdtangle_api.Rmd rename to Chapter_Crowdtangle_api.Rmd diff --git a/05-Facebook_ads_library_api.Rmd b/Chapter_Facebook_ads_library_api.Rmd similarity index 100% rename from 05-Facebook_ads_library_api.Rmd rename to Chapter_Facebook_ads_library_api.Rmd diff --git a/06-Genderize_api.Rmd b/Chapter_Genderize_api.Rmd similarity index 100% rename from 06-Genderize_api.Rmd rename to Chapter_Genderize_api.Rmd diff --git a/07-Github_api.Rmd b/Chapter_Github_api.Rmd similarity index 100% rename from 07-Github_api.Rmd rename to Chapter_Github_api.Rmd diff --git a/08-Google_news_api.Rmd b/Chapter_Google_news_api.Rmd similarity index 100% rename from 08-Google_news_api.Rmd rename to Chapter_Google_news_api.Rmd diff --git a/09-Google_nlp_api.Rmd b/Chapter_Google_nlp_api.Rmd similarity index 100% rename from 09-Google_nlp_api.Rmd rename to Chapter_Google_nlp_api.Rmd diff --git a/10-Google_places_api.Rmd b/Chapter_Google_places_api.Rmd similarity index 100% rename from 10-Google_places_api.Rmd rename to Chapter_Google_places_api.Rmd diff --git a/11-Google_speech.Rmd b/Chapter_Google_speech.Rmd similarity index 100% rename from 11-Google_speech.Rmd rename to Chapter_Google_speech.Rmd diff --git a/12-Google_translation_api.Rmd b/Chapter_Google_translation_api.Rmd similarity index 100% rename from 12-Google_translation_api.Rmd rename to Chapter_Google_translation_api.Rmd diff --git a/13-Googletrends_api.Rmd b/Chapter_Googletrends_api.Rmd similarity index 100% rename from 13-Googletrends_api.Rmd rename to Chapter_Googletrends_api.Rmd diff --git a/14-Instagram_basic_display_api.Rmd b/Chapter_Instagram_basic_display_api.Rmd similarity index 100% rename from 14-Instagram_basic_display_api.Rmd rename to Chapter_Instagram_basic_display_api.Rmd diff --git a/15-Instagram_graph_api.Rmd b/Chapter_Instagram_graph_api.Rmd similarity index 100% rename from 15-Instagram_graph_api.Rmd rename to Chapter_Instagram_graph_api.Rmd diff --git a/01-introduction.Rmd b/Chapter_Introduction.Rmd similarity index 100% rename from 01-introduction.Rmd rename to Chapter_Introduction.Rmd diff --git a/16-Mediacloud_api.Rmd b/Chapter_Mediacloud_api.Rmd similarity index 100% rename from 16-Mediacloud_api.Rmd rename to Chapter_Mediacloud_api.Rmd diff --git a/99-References_Appendix.rmd b/Chapter_References_Appendix.rmd similarity index 100% rename from 99-References_Appendix.rmd rename to Chapter_References_Appendix.rmd diff --git a/17-Twitter_api.Rmd b/Chapter_Twitter_api.Rmd similarity index 100% rename from 17-Twitter_api.Rmd rename to Chapter_Twitter_api.Rmd diff --git a/18-Wiki_api.Rmd b/Chapter_Wiki_api.Rmd similarity index 100% rename from 18-Wiki_api.Rmd rename to Chapter_Wiki_api.Rmd diff --git a/19-Youtube_api.Rmd b/Chapter_Youtube_api.Rmd similarity index 100% rename from 19-Youtube_api.Rmd rename to Chapter_Youtube_api.Rmd diff --git a/_bookdown.yml b/_bookdown.yml index ed8279a..442d8ec 100644 --- a/_bookdown.yml +++ b/_bookdown.yml @@ -5,23 +5,23 @@ language: chapter_name: 'Chapter ' rmd_files: - index.Rmd -- 01-introduction.Rmd -- 02-Best_practices.Rmd -- 03-Ckan_api.Rmd -- 04-Crowdtangle_api.Rmd -- 05-Facebook_ads_library_api.Rmd -- 06-Genderize_api.Rmd -- 07-Github_api.Rmd -- 08-Google_news_api.Rmd -- 09-Google_nlp_api.Rmd -- 10-Google_places_api.Rmd -- 11-Google_speech.Rmd -- 12-Google_translation_api.Rmd -- 13-Googletrends_api.Rmd -- 14-Instagram_basic_display_api.Rmd -- 15-Instagram_graph_api.Rmd -- 16-Mediacloud_api.Rmd -- 17-Twitter_api.Rmd -- 18-Wiki_api.Rmd -- 19-Youtube_api.Rmd -- 99-References_Appendix.rmd +- Chapter_Introduction.Rmd +- Chapter_Best_practices.Rmd +- Chapter_Ckan_api.Rmd +- Chapter_Crowdtangle_api.Rmd +- Chapter_Facebook_ads_library_api.Rmd +- Chapter_Genderize_api.Rmd +- Chapter_Github_api.Rmd +- Chapter_Google_news_api.Rmd +- Chapter_Google_nlp_api.Rmd +- Chapter_Google_places_api.Rmd +- Chapter_Google_speech.Rmd +- Chapter_Google_translation_api.Rmd +- Chapter_Googletrends_api.Rmd +- Chapter_Instagram_basic_display_api.Rmd +- Chapter_Instagram_graph_api.Rmd +- Chapter_Mediacloud_api.Rmd +- Chapter_Twitter_api.Rmd +- Chapter_Wiki_api.Rmd +- Chapter_Youtube_api.Rmd +- Chapter_References_Appendix.rmd diff --git a/figures/sort_chapters.R b/figures/sort_chapters.R index de1a46d..aa7b8f6 100644 --- a/figures/sort_chapters.R +++ b/figures/sort_chapters.R @@ -1,8 +1,9 @@ yaml_content <- read_yaml(here::here("_bookdown.yml")) all_rmds <- fs::path_file(fs::dir_ls(here::here(), regexp = "^.+\\.[rR]md$")) index_index <- which(all_rmds == "index.Rmd") -intro_index <- which(grepl("introduction", all_rmds)) +intro_index <- which(grepl("Introduction", all_rmds)) bp_index <- which(grepl("Best_practices", all_rmds)) -rmd_files <- all_rmds[c(index_index, intro_index, bp_index, setdiff(seq_along(all_rmds), c(index_index, intro_index, bp_index)))] +ref_index <- which(grepl("References_Appendix", all_rmds)) +rmd_files <- all_rmds[c(index_index, intro_index, bp_index, setdiff(seq_along(all_rmds), c(index_index, intro_index, bp_index, ref_index)), ref_index)] yaml_content$rmd_files <- rmd_files write_yaml(yaml_content, here::here("_bookdown.yml")) From 176d32ab90c7706b06cae23527ec0ad3a6e1523b Mon Sep 17 00:00:00 2001 From: chainsawriot Date: Thu, 24 Feb 2022 17:15:10 +0100 Subject: [PATCH 3/3] Declare `yaml`; Sort the chapters --- figures/sort_chapters.R | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/figures/sort_chapters.R b/figures/sort_chapters.R index aa7b8f6..eecce47 100644 --- a/figures/sort_chapters.R +++ b/figures/sort_chapters.R @@ -1,9 +1,14 @@ -yaml_content <- read_yaml(here::here("_bookdown.yml")) +yaml_content <- yaml::read_yaml(here::here("_bookdown.yml")) all_rmds <- fs::path_file(fs::dir_ls(here::here(), regexp = "^.+\\.[rR]md$")) index_index <- which(all_rmds == "index.Rmd") intro_index <- which(grepl("Introduction", all_rmds)) bp_index <- which(grepl("Best_practices", all_rmds)) ref_index <- which(grepl("References_Appendix", all_rmds)) -rmd_files <- all_rmds[c(index_index, intro_index, bp_index, setdiff(seq_along(all_rmds), c(index_index, intro_index, bp_index, ref_index)), ref_index)] + +## This step might not be needed because fs::path_file should have returned a sorted list. But for sanity. + +sorted_chapters <- sort(all_rmds[setdiff(seq_along(all_rmds), c(index_index, intro_index, bp_index, ref_index))]) + +rmd_files <- c(all_rmds[index_index], all_rmds[intro_index], all_rmds[bp_index], sorted_chapters, all_rmds[ref_index]) yaml_content$rmd_files <- rmd_files -write_yaml(yaml_content, here::here("_bookdown.yml")) +yaml::write_yaml(yaml_content, here::here("_bookdown.yml"))