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

Delint and debug #273

Merged
merged 11 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.coderabbit.yaml
.lintr
.codecov.yaml
^Makefile$
Expand Down
15 changes: 15 additions & 0 deletions .coderabbit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
language: "en-US"
early_access: false
reviews:
profile: "chill"
request_changes_workflow: false
high_level_summary: false
poem: false
review_status: true
collapse_walkthrough: false
auto_review:
enabled: true
drafts: false
chat:
auto_reply: false
25 changes: 12 additions & 13 deletions .lintr
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
linters: linters_with_defaults(
line_length_linter(305),
commented_code_linter = NULL,
object_name_linter = NULL,
indentation_linter = NULL,
infix_spaces_linter = NULL,
spaces_left_parentheses_linter = NULL,
seq_linter = NULL,
vector_logic_linter = NULL,
function_left_parentheses_linter = NULL,
semicolon_linter = NULL,
T_and_F_symbol_linter = NULL,
object_usage_linter = NULL
linters: linters_with_tags(
tags = c(
"default",
"best_practices_linters",
"common_mistakes",
"correctness",
"executing"
),
line_length_linter(305), # TODO — change to 120
seq_linter = NULL, # TODO - small refactor
cyclocomp_linter(complexity_limit = 16), # TODO - small refactor
object_name_linter = NULL # Probably never gonna remove this one
)
zachmayer marked this conversation as resolved.
Show resolved Hide resolved
19 changes: 14 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Makefile for R project

.PHONY: all install document test check-cran lint clean
.PHONY: all install document update-test-fixtures test check-cran fix-style lint clean

# Default target
all: install document test test-coverage check check-cran
all: fix-style install document test check-cran

# Install dependencies
install:
Expand All @@ -15,17 +15,26 @@ install:
document:
Rscript -e "devtools::document()"

# Update test fixtures
update-test-fixtures:
Rscript inst/data-raw/build_test_data.R

# Run unit tests
test:
Rscript -e "devtools::test(stop_on_failure=TRUE)"
Rscript -e "Sys.setenv(NOT_CRAN='true'); devtools::test(stop_on_failure=TRUE, stop_on_warning=TRUE)"

# Run R CMD check as CRAN
check-cran: document
Rscript -e "devtools::check(cran=T, remote=T, manual=T, error_on='note')"

# Auto lint the code
lint:
# Auto style the code
fix-style:
Rscript -e "styler::style_pkg()"
Rscript -e "styler::style_dir('inst/')"

# Check the code for lint
lint:
Rscript -e "lintr::lint_package()"

# Clean up generated files
clean:
Expand Down
56 changes: 29 additions & 27 deletions R/S3GenericExtenstions.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,32 @@
#' @export
#' @examples
#' \dontrun{
#' model_list1 <- caretList(Class ~ .,
#' data=Sonar, trControl = ctrl1,
#' model_list1 <- caretList(Class ~ .,
#' data = Sonar, trControl = ctrl1,
#' tuneList = list(
#' glm=caretModelSpec(method='glm', family='binomial'),
#' rpart=caretModelSpec(method='rpart')
#' ),
#' metric='ROC')
#' glm = caretModelSpec(method = "glm", family = "binomial"),
#' rpart = caretModelSpec(method = "rpart")
#' ),
#' metric = "ROC"
#' )
#'
#' model_list2 <- caretList(Class ~ .,
#' data=Sonar,
#' trControl = ctrl1,
#' tuneList = list(
#' glm=caretModelSpec(method='rpart'),
#' rpart=caretModelSpec(method='rf')
#' ),
#' metric='ROC')
#' data = Sonar,
#' trControl = ctrl1,
#' tuneList = list(
#' glm = caretModelSpec(method = "rpart"),
#' rpart = caretModelSpec(method = "rf")
#' ),
#' metric = "ROC"
#' )
#'
#' bigList <- c(model_list1, model_list2)
#' bigList <- c(model_list1, model_list2)
#' }
#'
c.caretList <- function(...) {

new_model_list <- unlist(lapply(list(...), function(x) {
if(! inherits(x, "caretList")) {
if(! inherits(x, "train")) stop("class of modelList1 must be 'caretList' or 'train'")
if (!inherits(x, "caretList")) {
if (!inherits(x, "train")) stop("class of modelList1 must be 'caretList' or 'train'")

## assuming this is a single train object
x <- list(x)
Expand Down Expand Up @@ -66,23 +67,24 @@ c.caretList <- function(...) {
#' @examples
#' \dontrun{
#' rpartTrain <- train(Class ~ .,
#' data=Sonar,
#' trControl = ctrl1,
#' method='rpart')
#' data = Sonar,
#' trControl = ctrl1,
#' method = "rpart"
#' )
#'
#' rfTrain <- train(Class ~ .,
#' data=Sonar,
#' trControl = ctrl1,
#' method='rf')
#' data = Sonar,
#' trControl = ctrl1,
#' method = "rf"
#' )
#'
#' bigList <- c(model_list1, model_list2)
#' bigList <- c(model_list1, model_list2)
#' }
#'
c.train <- function(...) {

new_model_list <- unlist(lapply(list(...), function(x) {
if(! inherits(x, "caretList")) {
if(! inherits(x, "train")) stop("class of modelList1 must be 'caretList' or 'train'")
if (!inherits(x, "caretList")) {
if (!inherits(x, "train")) stop("class of modelList1 must be 'caretList' or 'train'")

## assuming this is a single train object
x <- list(x)
Expand Down
15 changes: 9 additions & 6 deletions R/caretEnsemble-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,15 @@ NULL
#' @keywords data
NULL

#Hack to make data.table functions work with devtools::load_all
#http://stackoverflow.com/questions/23252231/r-data-table-breaks-in-exported-functions
#http://r.789695.n4.nabble.com/Import-problem-with-data-table-in-packages-td4665958.html
# Hack to make data.table functions work with devtools::load_all
# http://stackoverflow.com/questions/23252231/r-data-table-breaks-in-exported-functions
# http://r.789695.n4.nabble.com/Import-problem-with-data-table-in-packages-td4665958.html
assign(".datatable.aware", TRUE)

#Avoid false positives in R CMD CHECK:
# Avoid false positives in R CMD CHECK:
utils::globalVariables(
c(".fitted", ".resid", "method", "id", "yhat",
"ymax", "yavg", "ymin", "metric", "metricSD", "n"))
c(
".fitted", ".resid", "method", "id", "yhat",
"ymax", "yavg", "ymin", "metric", "metricSD", "n"
)
)
Loading
Loading