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

Add a list of all checks for each venue type #50

38 changes: 9 additions & 29 deletions R/register.R
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
CONFIG <- new.env()
# Registers can be further divided into filter subgroups
# For cases where an entry does not fall into any subgroup, it's rendered files
# are stored in a folder with its own name
CONFIG$FILTER_SUB_GROUPS <- list(
venues = list("community", "journal", "conference")
)
CONFIG$MD_COLUMNS_WIDTHS <- "|:-------|:--------------------------------|:------------------|:---|:--------------------------|:----------|"
CONFIG$REGISTER_COLUMNS <- list("Certificate", "Repository", "Type", "Issue", "Report", "Check date")
CONFIG$DICT_ORCID_ID_NAME <- list()
CONFIG$DIR_TEMP_REGISTER_CODECHECKER <- "docs/temp_register_codechecker.csv"
CONFIG$DICT_VENUE_NAMES <- list(
"journal (GigaScience)" = "GigaScience",
"journal (J Geogr Syst)" = "Journal of Geographical Systems",
"journal (J Archaeol Sci)" = "Journal of Archaeological Science",
"journal (GigaByte)" = "GigaByte",
"conference (AGILEGIS)" = "AGILEGIS",
"community (codecheck)" = "Codecheck",
"community (codecheck NL)" = "Codecheck NL",
"community (in press)" = "In press",
"community (preprint)" = "Preprint"
)


#' Function for rendering the register into different view
#'
#' NOTE: You should put a GitHub API token inth the environment variable `GITHUB_PAT` to fix rate limits. Acquire one at see https://github.com/settings/tokens.
Expand All @@ -45,10 +21,14 @@ CONFIG$DICT_VENUE_NAMES <- list(
register_render <- function(register = read.csv("register.csv", as.is = TRUE),
filter_by = c("venues", "codecheckers"),
outputs = c("html", "md", "json")) {
CONFIG$MD_REG_TEMPLATE <- system.file("extdata", "templates/template_register.md", package = "codecheck")
CONFIG$MD_NON_REG_TEMPLATE <- system.file("extdata", "templates/template_non_register.md", package = "codecheck")
# Loading config.R file
source(system.file("extdata", "config.R", package = "codecheck"))

register_table <- preprocess_register(register, filter_by)

# Setting number of codechecks now for later use. This is done to avoid double counting codechecks
# done by multiple authors.
CONFIG$NO_CODECHECKS <- nrow(register_table)

# Creating list of of register tables with indices being the filter types
list_register_tables <- c()
Expand All @@ -65,7 +45,7 @@ register_render <- function(register = read.csv("register.csv", as.is = TRUE),
}

# Rendering files
# if ("md" %in% outputs) render_register_mds(list_register_tables)
if ("md" %in% outputs) render_register_mds(list_register_tables)
if ("html" %in% outputs) {
render_register_htmls(list_register_tables)

Expand All @@ -74,11 +54,11 @@ register_render <- function(register = read.csv("register.csv", as.is = TRUE),
}
}
if ("json" %in% outputs) {
# render_register_jsons(list_register_tables)
render_register_jsons(list_register_tables)

for (filter in filter_by){
render_non_register_jsons(list_register_tables[[filter]], page_type = filter)
}

}

return(register_table)
Expand Down
2 changes: 1 addition & 1 deletion R/utils_create_filtered_register_csvs.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ get_output_dir <- function(filter, column_value) {
#' @param venue_name The venue_name obtained from the "Type" column of the register
#' @return The venue category. If the venue does not belong to any category NULL is returned
determine_venue_category <- function(venue_name){
list_venue_categories <- CONFIG$FILTER_SUB_GROUPS[["venues"]]
list_venue_categories <- CONFIG$FILTER_SUBCATEGORIES[["venues"]]
for (category in list_venue_categories){
if (grepl(category, venue_name, ignore.case=TRUE)) {
return(category)
Expand Down
2 changes: 1 addition & 1 deletion R/utils_render_register_mds.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ render_register_md <- function(filter, register_table, register_table_name, for_
register_table <- add_repository_links_md(register_table)
}
# Fill in the content
md_table <- load_md_template(CONFIG$MD_REG_TEMPLATE)
md_table <- load_md_template(CONFIG$TEMPLATE_DIR[["reg"]][["md_template"]])

markdown_content <- capture.output(kable(register_table, format = "markdown"))
md_table <- add_markdown_title(filter, md_table, register_table_name)
Expand Down
11 changes: 6 additions & 5 deletions R/utils_render_reigster_html.r
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,17 @@ generate_html_document_yml <- function(output_dir) {
#'
#' @importFrom whisker whisker.render
create_index_postfix_html <- function(output_dir, filter, register_table_name = NULL){
# When we have a reg table name, we adjusting the hrefs of the postfix

# When we have register table names, we are handling the case of reg tables
if (!is.null(register_table_name)){
postfix_template <- readLines(paste0(getwd(), "/docs/templates/reg_tables/index_postfix_template.html"), warn = FALSE)
postfix_template <- readLines(CONFIG$TEMPLATE_DIR[["reg"]][["postfix"]], warn = FALSE)
# Render the template with the correct hrefs
hrefs <- generate_html_postfix_hrefs_reg(filter, register_table_name)
}

# Generating the postfix for non-register table pages (e.g. list of venues and codecheckers)
else{
postfix_template <- readLines(paste0(getwd(), "/docs/templates/codecheckers_venues_list/index_postfix_template.html"), warn = FALSE)
postfix_template <- readLines(CONFIG$TEMPLATE_DIR[["non_reg"]][["postfix"]], warn = FALSE)
hrefs <- list(
json_href = paste0("https://codecheck.org.uk/register/", filter, "/index.json")
)
Expand All @@ -84,7 +85,7 @@ create_index_postfix_html <- function(output_dir, filter, register_table_name =
#' @param output_dir The output directory
create_index_prefix_html <- function(output_dir){
# Using the index_prefix_template
prefix_template <- readLines(paste0(getwd(), "/docs/templates/general/index_prefix_template.html"), warn = FALSE)
prefix_template <- readLines(CONFIG$TEMPLATE_DIR[["reg"]][["prefix"]], warn = FALSE)
writeLines(prefix_template, paste0(output_dir, "index_prefix.html"))
}

Expand All @@ -93,7 +94,7 @@ create_index_prefix_html <- function(output_dir){
#' @param output_dir The output directory
create_index_header_html <- function(output_dir){
# Using the index_header_template
header_template <- readLines(paste0(getwd(), "/docs/templates/general/index_header_template.html"), warn = FALSE)
header_template <- readLines(CONFIG$TEMPLATE_DIR[["reg"]][["header"]], warn = FALSE)

writeLines(header_template, paste0(output_dir, "index_header.html"))
}
Expand Down
49 changes: 24 additions & 25 deletions R/utils_render_table_codecheckers.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
#' @param list_codechecker_reg_tables The list of codechecker register tables. The indices are the ORCID IDs.
render_table_codecheckers_json <- function(list_codechecker_reg_tables){
list_orcid_ids <- names(list_codechecker_reg_tables)
# Check.names arg is set to FALSE so that column "ORCID ID" has the space
table_codecheckers <- data.frame(`ORCID ID`= list_orcid_ids, stringsAsFactors = FALSE, check.names = FALSE)
table_codecheckers <- data.frame(matrix(ncol=0, nrow = length(list_orcid_ids)), stringsAsFactors = FALSE)

col_names <- CONFIG$NON_REG_TABLE_COL_NAMES[["codechecker_table"]]

# Column- codechecker names
table_codecheckers$`Codechecker name` <- sapply(
X = table_codecheckers$`ORCID ID`,
table_codecheckers[[col_names[["codechecker"]]]] <- sapply(
X = list_orcid_ids,
FUN = function(orcid_id) {
paste0(CONFIG$DICT_ORCID_ID_NAME[orcid_id])
paste0(CONFIG$DICT_ORCID_ID_NAME[[orcid_id]])
}
)

table_codecheckers[[col_names[["orcid"]]]] <- list_orcid_ids

# Column- No. of codechecks
table_codecheckers$`No. of codechecks` <- sapply(
X = table_codecheckers$`ORCID ID`,
table_codecheckers[[col_names[["no_codechecks"]]]] <- sapply(
X = list_orcid_ids,
FUN = function(orcid_id) {
paste0(nrow(list_codechecker_reg_tables[[orcid_id]]))
}
)

# Arranging the column names
table_codecheckers <- table_codecheckers[, c("Codechecker name", "ORCID ID", "No. of codechecks")]

return(table_codecheckers)
}

Expand All @@ -36,44 +36,43 @@ render_table_codecheckers_json <- function(list_codechecker_reg_tables){
render_table_codecheckers_html <- function(list_codechecker_reg_tables){

list_orcid_ids <- names(list_codechecker_reg_tables)
table_codecheckers <- data.frame(ORCID_ID = list_orcid_ids, stringsAsFactors = FALSE)
col_names <- CONFIG$NON_REG_TABLE_COL_NAMES[["codechecker_table"]]

no_rows <- length(list_orcid_ids)

# Initializing the table
table_codecheckers <- data.frame(matrix(ncol= 0, nrow = no_rows), stringsAsFactors = FALSE)

# Column- codechecker names
# Each codechecker name will be a hyperlink to the register table
# with all their codechecks
table_codecheckers$`Codechecker name` <- sapply(
X = table_codecheckers$ORCID_ID,
table_codecheckers[col_names[["codechecker"]]] <- sapply(
X = list_orcid_ids,
FUN = function(orcid_id) {
codechecker_name <- CONFIG$DICT_ORCID_ID_NAME[orcid_id]
codechecker_name <- CONFIG$DICT_ORCID_ID_NAME[[orcid_id]]
paste0("[", codechecker_name, "](https://codecheck.org.uk/register/codecheckers/",
orcid_id, "/)")
}
)

# Column- ORCID ID link
table_codecheckers$ORCID_ID_Link <- sapply(
X = table_codecheckers$ORCID_ID,
# Column- ORCID ID
table_codecheckers[col_names[["orcid"]]] <- sapply(
X = list_orcid_ids,
FUN = function(orcid_id) {
paste0("[", orcid_id, "](https://orcid.org/", orcid_id, ")")
}
)
# Column- No. of codechecks
# Shown as "no_codechecks (sell all checks)" where "see all checks" links to the checks by
# the codechecker
table_codecheckers$`No. of codechecks` <- sapply(
X = table_codecheckers$ORCID_ID,
table_codecheckers[col_names[["no_codechecks"]]] <- sapply(
X = list_orcid_ids,
FUN = function(orcid_id) {
no_codechecks <- nrow(list_codechecker_reg_tables[[orcid_id]])
paste0(nrow(list_codechecker_reg_tables[[orcid_id]])," [(see all checks)](https://codecheck.org.uk/register/codecheckers/",
orcid_id, "/)")
}
)

# Drop the original ORCID_ID column and rename ORCID_ID_Link to ORCID_ID
table_codecheckers <- table_codecheckers[, c("Codechecker name", "ORCID_ID_Link", "No. of codechecks")]
names(table_codecheckers)[names(table_codecheckers) == "ORCID_ID_Link"] <- "ORCID ID"

table_codecheckers <- kable(table_codecheckers)
return(table_codecheckers)
}

24 changes: 17 additions & 7 deletions R/utils_render_table_non_registers.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,37 @@
#' @param list_reg_tables The list of register tables to link to in this html page
render_non_register_htmls <- function(list_reg_tables, page_type){
output_dir <- paste0("docs/", page_type, "/")
extra_text <- ""

no_codechecks <- sum(sapply(list_reg_tables, nrow))
if (page_type == "codecheckers"){
table <- render_table_codecheckers_html(list_reg_tables)
# Counting number of codecheckers based of number of codechecker reg tables
# The table is a kable table and hence we cannot count rows
no_codecheckers <- length(list_reg_tables)
subtext <- paste("In total,", no_codecheckers, "codecheckers contributed", no_codechecks, "codechecks")
# Using number of codechecks from CONFIG instead of "no. of codechecks" column to avoid double count
subtext <- paste("In total,", no_codecheckers, "codecheckers contributed", CONFIG$NO_CODECHECKS, "codechecks*")

# Extra text to explain why total_codechecks != SUM(no.of codechecks)
extra_text <- "<i>\\*Note that the total codechecks is less than the collective sum of
individual codecheckers' number of codechecks.
This is because some codechecks involved more than one codechecker.</i>"
}

else if (page_type == "venues"){
else if (page_type == "venues") {
table <- render_table_venues_html(list_reg_tables)

no_venues <- length(list_reg_tables)
subtext <- paste("In total,", no_codechecks, "codechecks were completed for", no_venues, "venues")
subtext <- paste("In total,", CONFIG$NO_CODECHECKS, "codechecks were completed for", no_venues, "venues")
}

# Creating and adjusting the markdown table
md_table <- load_md_template(CONFIG$MD_NON_REG_TEMPLATE)
table <- kable(table)
md_table <- load_md_template(CONFIG$TEMPLATE_DIR[["non_reg"]][["md_template"]])
title <- paste0("CODECHECK List of ", page_type)
md_table <- gsub("\\$title\\$", title, md_table)
md_table <- gsub("\\$subtitle\\$", subtext, md_table)
md_table <- gsub("\\$content\\$", paste(table, collapse = "\n"), md_table)
md_table <- gsub("\\$extra_text\\$", extra_text, md_table)

# Saving the table to a temp md file
temp_md_path <- paste0(output_dir, "temp.md")
Expand Down Expand Up @@ -61,13 +70,14 @@ render_non_register_htmls <- function(list_reg_tables, page_type){
render_non_register_jsons <- function(list_reg_tables, page_type){
output_dir <- paste0("docs/", page_type, "/")

if (page_type == "codeheckers"){
if (page_type == "codecheckers"){
table <- render_table_codecheckers_json(list_reg_tables)
}

else if (page_type == "venues") {
else if (page_type == "venues"){
table <- render_table_venues_json(list_reg_tables)
}

jsonlite::write_json(
table,
path = paste0(output_dir, "index.json"),
Expand Down
Loading