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 feature to filter register by venue #40

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5402c33
add util to create list venue sorted registers
angelina-momin May 13, 2024
858b1ff
Change render register md function
angelina-momin May 13, 2024
513f4b4
Add template for register md
angelina-momin May 13, 2024
cd6a00d
Update render register html
angelina-momin May 14, 2024
5c79b6b
move helper function determine_output_directory to top
angelina-momin May 14, 2024
ba9136d
move add_repository_links to rendering
angelina-momin May 15, 2024
c1c48a1
htmls rendered without errors
angelina-momin May 15, 2024
e68e9ee
render html is working without errors now
angelina-momin May 16, 2024
2ed32c4
render_register_json handles multiple register tables
angelina-momin May 16, 2024
c2f386b
render_register_json is now working
angelina-momin May 20, 2024
51cae78
fix mistake in adding repo links json
angelina-momin May 20, 2024
2748c8f
adjust and add docstrings
angelina-momin May 20, 2024
0bd7b47
Update function documentation
angelina-momin May 20, 2024
b9903d9
remove unnecessary imports in NAMESPACE
angelina-momin May 20, 2024
741d1eb
remove gsub from NAMESPACE
angelina-momin May 20, 2024
21584b8
Correct kable import in NAMESPACE
angelina-momin May 20, 2024
8136e7e
Update register_sort_venue documentation
angelina-momin May 20, 2024
cd59858
Add argument to check_certificate_id
angelina-momin May 20, 2024
06a9310
Add comment to html_document.yml file
angelina-momin May 21, 2024
9917bc9
Bump version
angelina-momin May 21, 2024
5c4f3b5
Correct preprocess_register docstring
angelina-momin May 21, 2024
cf7ad4f
changed R github worflow to pass with warnings
angelina-momin May 21, 2024
5087ee8
corrected folder structure
angelina-momin May 21, 2024
fe726bc
refactor everything
angelina-momin May 24, 2024
a403f02
added arguments to function
angelina-momin May 24, 2024
8f80674
error free
angelina-momin May 24, 2024
c297652
renamed venue sub group
angelina-momin May 24, 2024
8cb72dc
edited get_output_dir
angelina-momin May 24, 2024
e8aa1da
edit render register html
angelina-momin May 24, 2024
5319afb
Add docstrings
angelina-momin May 24, 2024
a0bdf9f
Run roxygen2
angelina-momin May 24, 2024
c9fe776
add missing importfrom
angelina-momin May 24, 2024
dc09680
Fixed md links
angelina-momin May 24, 2024
aeef50e
All html files now share one libs folder
angelina-momin Jun 19, 2024
1273653
Update render register md documentation
angelina-momin Jun 19, 2024
6f63ccc
Running without bugs
angelina-momin Jun 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
- name: Check
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "error", check_dir = "check")
shell: Rscript {0}

- name: Upload check results
Expand Down
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: codecheck
Title: Helper Functions for CODECHECK Project
Version: 0.1.0.9006
Version: 0.2.0
Authors@R:
c(person(given = "Stephen",
family = "Eglen",
Expand Down Expand Up @@ -32,10 +32,11 @@ Imports:
rorcid,
osfr,
httr,
zen4R
zen4R,
whisker
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.1
RoxygenNote: 7.3.1
VignetteBuilder: knitr
Suggests:
tinytest,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ importFrom(stringr,str_replace_all)
importFrom(utils,capture.output)
importFrom(utils,read.csv)
importFrom(utils,tail)
importFrom(whisker,whisker.render)
importFrom(xtable,xtable)
importFrom(yaml,read_yaml)
importFrom(yaml,yaml.load)
Expand Down
29 changes: 24 additions & 5 deletions R/register.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
CONFIG <- new.env()
CONFIG$FILTER_SUB_GROUPS <- list(
venues = list("community", "journal", "conference", "codecheck nl")
)
CONFIG$MD_COLUMNS_WIDTHS <- "|:-------|:--------------------------------|:------------------|:---|:--------------------------|:----------|"

#' 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 @@ -19,14 +25,27 @@
#'
#' @export
register_render <- function(register = read.csv("register.csv", as.is = TRUE),
filter_by = c("venues"),
outputs = c("html", "md", "json")) {
CONFIG$MD_TEMPLATE <- system.file("extdata", "templates/template_register.md", package = "codecheck")

register_table <- preprocess_register(register)

md_columns_widths <- "|:-------|:--------------------------------|:------------------|:---|:--------------------------|:----------|"
# Creating list of of register tables with indices being the filter types
list_register_tables <- c()
list_register_tables[["none"]] <- list("original"= register_table)

if (length(filter_by)!=0){
# Creating filtered register csvs
create_filtered_register_csvs(filter_by, register)
# Creating and adding filtered registered tables to list of tables
list_register_tables <- add_filtered_register_tables(list_register_tables, register_table, filter_by)
}

if ("md" %in% outputs) render_register_md(register_table, md_columns_widths)
if ("html" %in% outputs) render_register_html(register_table, register, md_columns_widths)
if ("json" %in% outputs) render_register_json(register_table, register)
# Rendering files
if ("md" %in% outputs) render_register_mds(list_register_tables)
if ("html" %in% outputs) render_register_htmls(list_register_tables)
if ("json" %in% outputs) render_register_jsons(list_register_tables)

return(register_table)
}
Expand Down Expand Up @@ -57,7 +76,7 @@ register_check <- function(register = read.csv("register.csv", as.is = TRUE),

# check certificate IDs if there is a codecheck.yml
codecheck_yaml <- get_codecheck_yml(entry$Repository)
check_certificate_id(codecheck_yaml)
check_certificate_id(entry, codecheck_yaml)
check_issue_status(entry)
cat("Completed checking registry entry", toString(register[i, "Certificate"]), "\n")
}
Expand Down
82 changes: 82 additions & 0 deletions R/utils_create_filtered_register_csvs.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#' Creates filtered register csv files
#'
#' Each csv file is saved in the appropriate output_dir.
#'
#' @param filter_by A vector of strings specifying the names of the columns to filter by.
#' @param register A dataframe representing the register data to be filtered.
create_filtered_register_csvs <- function(filter_by, register){

for (filter in filter_by){
column_name <- determine_filter_column_name(filter)
unique_values <- unique(register[[column_name]])

for (value in unique_values) {
filtered_register <- register[register[[column_name]]==value, ]
output_dir <- paste0(get_output_dir(filter, value), "register.csv")

if (!dir.exists(dirname(output_dir))) {
dir.create(dirname(output_dir), recursive = TRUE, showWarnings = TRUE)
}

write.csv(filtered_register, output_dir, row.names=FALSE)
}
}
}

#' Determines the register table's column name to filter the data by.
#'
#' @param filter The filter name
#' @return The column name to filter by
determine_filter_column_name <- function(filter) {
filter_column_name <- switch(filter,
"venues" = "Type",
NULL # Default case is set to NULL
)
if (is.null(filter_column_name)) {
stop(paste("Filter", filter, "is not recognized."))
}

return(filter_column_name)
}

#' Gets the output dir depending on the filter name and the value of the filtered column
#'
#' @param filter The filter name
#' @param column_value The value of the column the filter applies to
#' @return The directory to save files to
get_output_dir <- function(filter, column_value) {
if (filter=="none"){
return(paste0("docs/"))
}

else if (filter=="venues"){
venue_category <- determine_venue_category(column_value)
# In case the venue_category itself has no further subgroups we do not need subgroups
if (venue_category==tolower(column_value)){
return(paste0("docs/", filter, "/", gsub(" ", "_", venue_category), "/"))
}

# Removing the venue category to obtain the venue name and replace the brackets
venue_name <- trimws(gsub("[()]", "", gsub(venue_category, "", column_value)))
venue_name <- gsub(" ", "_", venue_name)
return(paste0("docs/", filter, "/", venue_category, "/", venue_name, "/")) }

else{
return(paste0("docs/", filter, "/", gsub(" ", "_", tolower(column_value)), "/"))
}
}

#' Determines the venue category based on the venue_name
#'
#' @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 the venue_name is returned
determine_venue_category <- function(venue_name){
list_venue_categories <- CONFIG$FILTER_SUB_GROUPS[["venues"]]
for (category in list_venue_categories){
if (grepl(category, venue_name, ignore.case=TRUE)) {
return(category)
}
}
warning(paste("Register venue", venue_name, "does not fall into any of the following venue categories:", toString(list_venue_categories)))
return(venue_name)
}
36 changes: 36 additions & 0 deletions R/utils_filter_register_table.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#' Function for adding filtered register tables to a list based on specified filters.
#' Each entry in the resulting list is a filtered register table by the filter type provided.
#'
#' @param list_register_tables A list to store the filtered tables
#' @param register_table The register table to filter
#' @param filter_by A vector of strings specifying the filter types
#' @return A list of filtered register tables
add_filtered_register_tables <- function(list_register_tables, register_table, filter_by) {

for (filter in filter_by){
list_register_tables[[filter]] <- create_filtered_register_tables(register_table, filter)
}

return(list_register_tables)
}

#' Function for creating a list of register tables that is filtered based on the filter type.
#' Each entry in the resulting list is the filtered register table with index corresponding to unique values in that column.
#'
#' @param register_table The register table
#' @param filter The filter name
#' @return A list of filtered register tables
create_filtered_register_tables <- function(register_table, filter) {
list_filtered_register_tables <- list()

filter_column_name <- determine_filter_column_name(filter)
unique_values <- unique(register_table[[filter_column_name]])
# Loop over the unique values. We create a sorted table for each value
for (value in unique_values) {
filtered_table <- register_table[register_table[[filter_column_name]]==value, ]
rownames(filtered_table) <- NULL # Reset row names to remove row numbers
list_filtered_register_tables[[value]] <- filtered_table
}

return(list_filtered_register_tables)
}
61 changes: 7 additions & 54 deletions R/utils_preprocess_register.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ register_clear_cache <- function() {
unlink(path, recursive = TRUE)
}

#' Function for adding clickable links to the repor for each entry in the register table.
#' Function for adding clickable links to the report for each entry in the register table.
#'
#' @param register_table The register table
#' @param register The register from the register.csv file
#' @return register_table

#' @return The adjusted register table
add_report_links <- function(register_table, register) {

reports <- c()
Expand All @@ -39,8 +38,7 @@ add_report_links <- function(register_table, register) {
#'
#' @param register_table The register table
#' @param register The register from the register.csv file
#' @return register_table

#' @return The adjusted register table
add_issue_number_links <- function(register_table, register) {
register_table$Issue <- sapply(
X = register$Issue,
Expand All @@ -60,53 +58,11 @@ add_issue_number_links <- function(register_table, register) {
return(register_table)
}

#' Function for adding repository links to each report in the register table.
#'
#' @param register_table The register table
#' @param register The register from the register.csv file
#' @return register_table

add_repository_links <- function(register_table, register) {
register_table$Repository <- sapply(
X = register$Repository,
FUN = function(repository) {
spec <- parse_repository_spec(repository)
if (!any(is.na(spec))) {
urrl <- "#"

switch(spec["type"],
"github" = {
urrl <- paste0("https://github.com/", spec[["repo"]])
paste0("[", spec[["repo"]], "](", urrl, ")")
},
"osf" = {
urrl <- paste0("https://osf.io/", spec[["repo"]])
paste0("[", spec[["repo"]], "](", urrl, ")")
},
"gitlab" = {
urrl <- paste0("https://gitlab.com/", spec[["repo"]])
paste0("[", spec[["repo"]], "](", urrl, ")")
},

# Type is none of the above
{
repository
}
)
} else {
repository
}
}
)
return(register_table)
}

#' Function for adding check time to each report in the register table.
#'
#' @param register_table The register table
#' @param register The register from the register.csv file
#' @return register_table

#' @return The adjusted register table
add_check_time <- function(register_table, register) {
check_times <- c()

Expand All @@ -127,16 +83,13 @@ add_check_time <- function(register_table, register) {
return(register_table)
}

#' Function for preprocessing the register to create and return the register_table.
#'
#' @param register_table The register table
#' @return register_table

#' Function for preprocessing the register to create and return the preprocessed register table.
#' @param register The register
#' @return The preprocessed register table
preprocess_register <- function(register) {
register_table <- register
register_table <- add_report_links(register_table, register)
register_table <- add_issue_number_links(register_table, register)
register_table <- add_repository_links(register_table, register)
register_table <- add_check_time(register_table, register)
return(register_table)
}
5 changes: 2 additions & 3 deletions R/utils_register_check.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#' If there is a mismatch a stop is sent. Else a warning is thrown.
#'
#' @param codecheck_yaml The codecheck yaml file
#' @param entry The registry entry
#' @return None

check_certificate_id <- function(codecheck_yaml) {
check_certificate_id <- function(entry, codecheck_yaml) {
# Codecheck.yml found, proceeding to check certificate id
if (!is.null(codecheck_yaml)) {
# validate config file
Expand All @@ -30,7 +30,6 @@ check_certificate_id <- function(codecheck_yaml) {
#'
#' @param entry The codecheck entry
#' @return None

check_issue_status <- function(entry) {
if (!is.na(entry$Issue)) {
# get the status and labels from an issue
Expand Down
Loading
Loading