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 linter CI #167

Merged
merged 47 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
ec2afa6
replaced purrr with lapply in plot_elbow and wrote an extra test
Nov 18, 2021
08d398c
change purrr with Map in sample_mallows
Nov 18, 2021
0bdf650
replaced purrr with lapply in compute_mallows_mixtures
Nov 18, 2021
0233d6d
removed purrr from compute_posterior_intervals
osorensen Nov 18, 2021
50274fa
removed purrr from assess_convergence
osorensen Nov 18, 2021
53ddf65
removed purrr from rank conversion
osorensen Nov 18, 2021
5f42341
replaced purrr with vapply et al in print function and added test
osorensen Nov 18, 2021
bab13e8
removed purrr from compute_mallows
osorensen Nov 18, 2021
34c34bd
removed purrr from generate_constraints and from a test
osorensen Nov 18, 2021
611e64b
removed purrr from Imports and incremented development version
osorensen Nov 18, 2021
a50d991
removed library call to purrr
osorensen Nov 18, 2021
ad755f7
replaced map with lapply in example
osorensen Nov 18, 2021
12750a2
removed another call to map
osorensen Nov 18, 2021
2b03f6d
hope I soon have removed every piece of purrr
osorensen Nov 18, 2021
4456362
updated docs
osorensen Nov 18, 2021
9c59bc0
Got master branch into develop
osorensen Nov 18, 2021
f3cae83
Untidyr (#154)
osorensen Nov 19, 2021
98b263e
Untidyr (#156)
osorensen Nov 19, 2021
2514f11
Removed permfun.R and remaining source of it
wleoncio Nov 19, 2021
e241d5f
SMC-Mallows (#157)
wleoncio Nov 22, 2021
295b33d
corrected a bunch of typos and updated readme
osorensen Nov 22, 2021
87697ee
corrected more typos with devtools::spellcheck()
osorensen Nov 22, 2021
93b3702
accidentally deleted vignettes/BayesMallows.pdf in previous commit. f…
osorensen Nov 22, 2021
a229ab4
resolved conflicts in description and news
osorensen Nov 24, 2021
7edab0b
Convert MAP output to tibble (fixes #163) (#164)
wleoncio Dec 3, 2021
15519d7
Changed classes for compute_posterior_interval methods (#80)
wleoncio Dec 3, 2021
8e31043
Added tests to check BM and SMC classes (#80)
wleoncio Dec 3, 2021
37dfaf9
Merge pull request #165 from ocbe-uio/fix-classes
wleoncio Dec 3, 2021
e2a7df6
Implement generics to close #80 (#161)
wleoncio Dec 3, 2021
528a78d
incremented version number and updated CRAN note
osorensen Dec 3, 2021
5429afc
corrected spelling error in smc vignette
osorensen Dec 3, 2021
16378f7
Merge branch 'master' into develop
osorensen Dec 3, 2021
3801b14
recompiled documentation after resolving conflicts with master branch
osorensen Dec 3, 2021
4d1a73c
recompiled readme and update some citations
osorensen Dec 3, 2021
1815f8e
Merge branch 'master' into develop
wleoncio Dec 6, 2021
1ee6a88
Merge ocbe-uio/develop into develop
wleoncio Dec 6, 2021
406f802
Added linter CI workflow
wleoncio Dec 6, 2021
6b53f7e
Using <- for assignment
wleoncio Dec 6, 2021
39f4080
Removed commented out code
wleoncio Dec 6, 2021
bacc949
Improved spacing around commas and operators
wleoncio Dec 6, 2021
f0235a1
Replaced tab with space for indentation
wleoncio Dec 6, 2021
f41d7ff
Fixed spacing before curly brace
wleoncio Dec 6, 2021
1e66f1e
Replaced single quotes with double
wleoncio Dec 6, 2021
0df3526
Adjusting space before left parenthesis
wleoncio Dec 6, 2021
59dd9a4
Replaced F with FALSE
wleoncio Dec 6, 2021
be5cf49
Removed superfluous trailing blank lines
wleoncio Dec 6, 2021
de55d2a
Removed unnecessary concatenation
wleoncio Dec 6, 2021
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
71 changes: 71 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
#
# See https://github.com/r-lib/actions/tree/master/examples#readme for
# additional example workflows available for the R community.

# ======================================================== #
# Determines when the action is triggered #
# ======================================================== #

on: [push, pull_request]
name: linter

# ======================================================== #
# Determine actions to take #
# ======================================================== #

jobs:
lint:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checking out the repository
uses: actions/checkout@v2

- name: Setting up R
uses: r-lib/actions/setup-r@v1
with:
use-public-rspm: true

- name: Installing dependencies
uses: r-lib/actions/setup-r-dependencies@v1
with:
extra-packages: lintr

- name: Picking on the coding style
run: |
library(lintr)
excluded_files <- list(
"inst/examples/compute_consensus_example.R",
"inst/examples/compute_mallows_example.R",
"inst/examples/compute_mallows_mixtures_example.R",
"inst/examples/compute_posterior_intervals_example.R",
"inst/examples/estimate_partition_function_example.R",
"inst/examples/generate_constraints_example.R",
"inst/examples/generate_initial_ranking_example.R",
"inst/examples/generate_transitive_closure_example.R",
"inst/examples/label_switching_example.R",
"inst/examples/obs_freq_example.R",
"inst/examples/plot_top_k_example.R",
"inst/examples/plot.BayesMallows_example.R"
)
style_rules <- list(
absolute_path_linter, assignment_linter, closed_curly_linter,
commas_linter, commented_code_linter, cyclocomp_linter,
equals_na_linter, function_left_parentheses_linter,
infix_spaces_linter, line_length_linter, no_tab_linter,
nonportable_path_linter, object_length_linter,
open_curly_linter, paren_brace_linter, pipe_continuation_linter,
semicolon_terminator_linter, seq_linter, single_quotes_linter,
spaces_inside_linter, spaces_left_parentheses_linter,
T_and_F_symbol_linter, todo_comment_linter,
trailing_blank_lines_linter, trailing_whitespace_linter,
undesirable_function_linter, undesirable_operator_linter,
unneeded_concatenation_linter
)
lint_package(linters = style_rules, exclusions = excluded_files)
shell: Rscript {0}
1 change: 0 additions & 1 deletion R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -649,4 +649,3 @@ metropolis_hastings_aug_ranking_pseudo <- function(alpha, rho, n_items, partial_
metropolis_hastings_rho <- function(alpha, n_items, rankings, metric, rho, leap_size) {
.Call(`_BayesMallows_metropolis_hastings_rho`, alpha, n_items, rankings, metric, rho, leap_size)
}

8 changes: 4 additions & 4 deletions R/all_topological_sorts.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Translation to R of C++ and Python code found here
# https://www.geeksforgeeks.org/all-topological-sorts-of-a-directed-acyclic-graph/
all_topological_sorts <- function(graph, path, discovered, n_items){
all_topological_sorts <- function(graph, path, discovered, n_items) {
flag <- FALSE

for(i in seq_len(n_items)){
if(attr(graph, "indegree")[[i]] == 0 && !discovered[[i]]){
for (i in seq_len(n_items)) {
if (attr(graph, "indegree")[[i]] == 0 && !discovered[[i]]) {
attr(graph, "indegree")[graph[[i]]] <- attr(graph, "indegree")[graph[[i]]] - 1

path <- c(path, i)
Expand All @@ -18,5 +18,5 @@ all_topological_sorts <- function(graph, path, discovered, n_items){
flag <- TRUE
}
}
if(length(path) == n_items) print(path)
if (length(path) == n_items) print(path)
}
64 changes: 32 additions & 32 deletions R/assess_convergence.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,64 +26,64 @@
#' @export
#'
assess_convergence <- function(model_fit, parameter = "alpha", items = NULL,
assessors = NULL){
assessors = NULL) {

stopifnot(inherits(model_fit, "BayesMallows") ||
inherits(model_fit, "BayesMallowsMixtures"))

if(parameter == "alpha") {
if(inherits(model_fit, "BayesMallows")){
if (parameter == "alpha") {
if (inherits(model_fit, "BayesMallows")) {
m <- model_fit$alpha
trace_alpha(m, FALSE)
} else if(inherits(model_fit, "BayesMallowsMixtures")){
m <- do.call(rbind, lapply(model_fit, function(x){
} else if (inherits(model_fit, "BayesMallowsMixtures")) {
m <- do.call(rbind, lapply(model_fit, function(x) {
dplyr::mutate(x$alpha,
cluster = as.character(.data$cluster),
n_clusters = x$n_clusters)
}))
trace_alpha(m, TRUE)
}

} else if(parameter == "rho"){
if(inherits(model_fit, "BayesMallows")){
} else if (parameter == "rho") {
if (inherits(model_fit, "BayesMallows")) {
trace_rho(model_fit, items)
} else if(inherits(model_fit, "BayesMallowsMixtures")){
} else if (inherits(model_fit, "BayesMallowsMixtures")) {
cowplot::plot_grid(plotlist = lapply(model_fit, trace_rho, clusters = TRUE, items = items))
}

} else if(parameter == "Rtilde") {
} else if (parameter == "Rtilde") {

if(inherits(model_fit, "BayesMallows")){
if (inherits(model_fit, "BayesMallows")) {
trace_rtilde(model_fit, items, assessors)
} else if(inherits(model_fit, "BayesMallowsMixtures")){
} else if (inherits(model_fit, "BayesMallowsMixtures")) {
stop("Trace plots of augmented data not supported for BayesMallowsMixtures. Please rerun each component k using the k-th list element.")
}
} else if (parameter == "cluster_probs"){
if(inherits(model_fit, "BayesMallows")){
} else if (parameter == "cluster_probs") {
if (inherits(model_fit, "BayesMallows")) {
m <- model_fit$cluster_probs
} else if(inherits(model_fit, "BayesMallowsMixtures")){
m <- do.call(rbind, lapply(model_fit, function(x){
} else if (inherits(model_fit, "BayesMallowsMixtures")) {
m <- do.call(rbind, lapply(model_fit, function(x) {
dplyr::mutate(x$cluster_probs,
cluster = as.character(.data$cluster),
n_clusters = x$n_clusters)
}))
}
trace_cluster_probs(m)

} else if (parameter == "theta"){
} else if (parameter == "theta") {
trace_theta(model_fit)
} else {
stop("parameter must be either \"alpha\", \"rho\", \"augmentation\", \"cluster_probs\", or \"theta\".")
}
}

trace_alpha <- function(m, clusters){
trace_alpha <- function(m, clusters) {
# Create the diagnostic plot for alpha
p <- ggplot2::ggplot(m, ggplot2::aes(x = .data$iteration, y = .data$value)) +
ggplot2::xlab("Iteration") +
ggplot2::ylab(expression(alpha))

if(!clusters){
if (!clusters) {
p <- p + ggplot2::geom_line()
} else {
p <- p +
Expand All @@ -97,16 +97,16 @@ trace_alpha <- function(m, clusters){
return(p)
}

trace_rho <- function(model_fit, items, clusters = model_fit$n_clusters > 1){
trace_rho <- function(model_fit, items, clusters = model_fit$n_clusters > 1) {

if(is.null(items) && model_fit$n_items > 5){
if (is.null(items) && model_fit$n_items > 5) {
message("Items not provided by user. Picking 5 at random.")
items <- sample.int(model_fit$n_items, 5)
} else if (is.null(items) && model_fit$n_items > 0) {
items <- seq.int(from = 1, to = model_fit$n_items)
}

if(!is.character(items)){
if (!is.character(items)) {
items <- model_fit$items[items]
}

Expand All @@ -118,40 +118,40 @@ trace_rho <- function(model_fit, items, clusters = model_fit$n_clusters > 1){
ggplot2::xlab("Iteration") +
ggplot2::ylab(expression(rho))

if(clusters){
if (clusters) {
p <- p + ggplot2::facet_wrap(ggplot2::vars(.data$cluster))
}

return(p)
}


trace_rtilde <- function(model_fit, items, assessors, ...){
trace_rtilde <- function(model_fit, items, assessors, ...) {


if(!model_fit$save_aug){
if (!model_fit$save_aug) {
stop("Please rerun with compute_mallows with save_aug = TRUE")
}

if(is.null(items) && model_fit$n_items > 5){
if (is.null(items) && model_fit$n_items > 5) {
message("Items not provided by user. Picking 5 at random.")
items <- sample.int(model_fit$n_items, 5)
} else if (is.null(items) && model_fit$n_items > 0) {
items <- seq.int(from = 1, to = model_fit$n_items)
}

if(is.null(assessors) && model_fit$n_assessors > 5){
if (is.null(assessors) && model_fit$n_assessors > 5) {
message("Assessors not provided by user. Picking 5 at random.")
assessors <- sample.int(model_fit$n_assessors, 5)
} else if (is.null(assessors) && model_fit$n_assessors > 0) {
assessors <- seq.int(from = 1, to = model_fit$n_assessors)
} else if(!is.null(assessors)) {
if(length(setdiff(assessors, seq(1, model_fit$n_assessors, 1))) > 0) {
} else if (!is.null(assessors)) {
if (length(setdiff(assessors, seq(1, model_fit$n_assessors, 1))) > 0) {
stop("assessors vector must contain numeric indices between 1 and the number of assessors")
}
}

if(is.factor(model_fit$augmented_data$item) && is.numeric(items)){
if (is.factor(model_fit$augmented_data$item) && is.numeric(items)) {
items <- levels(model_fit$augmented_data$item)[items]
}
df <- dplyr::filter(model_fit$augmented_data,
Expand All @@ -169,7 +169,7 @@ trace_rtilde <- function(model_fit, items, assessors, ...){
}


trace_cluster_probs <- function(m){
trace_cluster_probs <- function(m) {

ggplot2::ggplot(m, ggplot2::aes(x = .data$iteration, y = .data$value,
color = .data$cluster)) +
Expand All @@ -184,8 +184,8 @@ trace_cluster_probs <- function(m){
}


trace_theta <- function(model_fit){
if(is.null(model_fit$theta) || length(model_fit$theta) == 0){
trace_theta <- function(model_fit) {
if (is.null(model_fit$theta) || length(model_fit$theta) == 0) {
stop("Theta not available. Run compute_mallows with error_model = 'bernoulli'.")
}
# Create the diagnostic plot for theta
Expand Down
12 changes: 6 additions & 6 deletions R/assign_cluster.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
#'
#' @export
#'
assign_cluster <- function(model_fit, burnin = model_fit$burnin, soft = TRUE, expand = FALSE){
assign_cluster <- function(model_fit, burnin = model_fit$burnin, soft = TRUE, expand = FALSE) {

if(is.null(burnin)){
if (is.null(burnin)) {
stop("Please specify the burnin.")
}
if(is.null(model_fit$cluster_assignment)){
if (is.null(model_fit$cluster_assignment)) {
stop("Rerun compute_mallows with save_clus=TRUE.")
}
stopifnot(burnin < model_fit$nmc)
Expand All @@ -53,8 +53,8 @@ assign_cluster <- function(model_fit, burnin = model_fit$burnin, soft = TRUE, ex
df <- dplyr::ungroup(df)
df <- dplyr::rename(df, cluster = .data$value)

if(expand){
df <- do.call(rbind, lapply(split(df, f = df$assessor), function(dd){
if (expand) {
df <- do.call(rbind, lapply(split(df, f = df$assessor), function(dd) {
dd2 <- merge(dd, expand.grid(cluster = unique(df$cluster)), by = "cluster",
all = TRUE)
dd2$assessor <- unique(dd$assessor)
Expand All @@ -78,7 +78,7 @@ assign_cluster <- function(model_fit, burnin = model_fit$burnin, soft = TRUE, ex
# Join map back onto df
df <- dplyr::inner_join(df, map, by = "assessor")

if(!soft){
if (!soft) {
df <- dplyr::filter(df, .data$cluster == .data$map_cluster)
df <- dplyr::select(df, -.data$cluster)
}
Expand Down
Loading