Skip to content

Commit

Permalink
Merge pull request #51 from rsquaredacademy/develop
Browse files Browse the repository at this point in the history
Release prep
  • Loading branch information
aravindhebbali authored May 13, 2020
2 parents d18a19c + 6ef3c0a commit ea92edb
Show file tree
Hide file tree
Showing 80 changed files with 57,544 additions and 1,655 deletions.
11 changes: 5 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ sudo: false

matrix:
include:
- r: devel
- r: release
- r: release
os: osx
osx_image: xcode8.3
before_install:
- sudo tlmgr install framed titling
- r: devel
- r: 3.6
- r: 3.5
- r: 3.4
- r: 3.3

r_packages:
- covr
Expand Down
31 changes: 13 additions & 18 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: rbin
Type: Package
Title: Tools for Binning Data
Version: 0.1.2.9000
Version: 0.2.0
Authors@R: person("Aravind", "Hebbali", email = "hebbali.aravind@gmail.com", role = c("aut", "cre"))
Description: Manually bin data using weight of evidence and information value. Includes other binning
methods such as equal length, quantile and winsorized. Options for combining levels of categorical
Expand All @@ -11,29 +11,24 @@ License: MIT + file LICENSE
URL: https://github.com/rsquaredacademy/rbin, https://rbin.rsquaredacademy.com
BugReports: https://github.com/rsquaredacademy/rbin/issues
Depends:
R (>= 3.6)
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.1.1
R (>= 3.3)
Imports:
DescTools,
dplyr,
forcats,
data.table,
ggplot2,
stats,
utils
Suggests:
covr,
graphics,
magrittr,
knitr,
miniUI,
recipes,
rlang,
rmarkdown,
rstudioapi,
shiny,
stats,
tibble,
utils
Suggests:
covr,
testthat,
vdiffr,
knitr,
rmarkdown
vdiffr
VignetteBuilder: knitr
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.0
19 changes: 15 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

S3method(plot,rbin_equal_freq)
S3method(plot,rbin_equal_length)
S3method(plot,rbin_factor)
S3method(plot,rbin_manual)
Expand All @@ -12,7 +13,9 @@ S3method(print,rbin_manual)
S3method(print,rbin_quantiles)
S3method(print,rbin_winsorize)
S3method(rbin_equal_freq,default)
S3method(rbin_equal_length,default)
S3method(rbin_factor,default)
S3method(rbin_manual,default)
S3method(rbin_winsorize,default)
export(rbinAddin)
export(rbinFactorAddin)
Expand All @@ -25,8 +28,16 @@ export(rbin_factor_create)
export(rbin_manual)
export(rbin_quantiles)
export(rbin_winsorize)
importFrom(magrittr,"%<>%")
importFrom(magrittr,"%>%")
importFrom(rlang,"!!")
importFrom(rlang,":=")
importFrom(data.table,":=")
importFrom(data.table,.N)
importFrom(data.table,data.table)
importFrom(data.table,setDF)
importFrom(data.table,setorder)
importFrom(stats,na.omit)
importFrom(stats,quantile)
importFrom(utils,globalVariables)
importFrom(utils,head)
importFrom(utils,install.packages)
importFrom(utils,menu)
importFrom(utils,packageVersion)
importFrom(utils,tail)
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# rbin 0.2.0

This is a minor release for bug fixes and internal changes.

# rbin 0.1.2

* This is a patch release to fix CRAN note.
Expand Down
36 changes: 18 additions & 18 deletions R/rbin-addins.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@
#'
rbinAddin <- function(data = NULL) {

check_suggests('shiny')
check_suggests('miniUI')
check_suggests('rstudioapi')

context <- rstudioapi::getActiveDocumentContext()
text <- context$selection[[1]]$text
default_data <- text

if (is.null(data)) {
if (nzchar(default_data)) {
data <- default_data
}
}
}

if (any(class(data) %in% c("data.frame","tibble","tbl_df"))) {
Expand Down Expand Up @@ -48,7 +52,7 @@ rbinAddin <- function(data = NULL) {
shiny::textInput("mydata", "Data Name", value = mydata)
)
)

)
)
)
Expand All @@ -71,10 +75,10 @@ rbinAddin <- function(data = NULL) {
shiny::fluidRow(
shiny::column(4,
shiny::h4('Cut Points'),
shiny::p('For manual binning, you need to specify the cut points for the bins. `rbin`
follows the left closed and right open interval for creating bins. The
number of cut points you specify is one less than the number of bins you
want to create i.e. if you want to create 10 bins, you need to specify only
shiny::p('For manual binning, you need to specify the cut points for the bins. `rbin`
follows the left closed and right open interval for creating bins. The
number of cut points you specify is one less than the number of bins you
want to create i.e. if you want to create 10 bins, you need to specify only
9 cut points. View the vignette or documentation for more information.')
),
shiny::column(8, align = 'center',
Expand All @@ -86,7 +90,7 @@ rbinAddin <- function(data = NULL) {
shiny::actionButton("create_bins", "Create Bins")
)
)
)
)
)
),
miniUI::miniTabPanel("Bins", icon = shiny::icon("table"),
Expand All @@ -112,7 +116,7 @@ rbinAddin <- function(data = NULL) {
)
)
)


server <- function(input, output, session) {

Expand Down Expand Up @@ -171,13 +175,11 @@ rbinAddin <- function(data = NULL) {
})

down_bins <- shiny::reactive({
compute_bins() %>%
magrittr::use_series(bins) %>%
dplyr::select(cut_point, bin_count, good, bad, woe, iv)
compute_bins()$bins[c('cut_point', 'bin_count', 'good', 'bad', 'woe', 'iv')]
})

output$woe_manual <- shiny::renderPrint({
compute_bins()
compute_bins()
})

output$woe <- shiny::renderPlot({
Expand Down Expand Up @@ -220,7 +222,7 @@ rbinFactorAddin <- function(data = NULL) {
if (is.null(data)) {
if(nzchar(default_data)) {
data <- default_data
}
}
}

if (any(class(data) %in% c("data.frame","tibble","tbl_df"))) {
Expand Down Expand Up @@ -350,8 +352,8 @@ rbinFactorAddin <- function(data = NULL) {
shiny::updateSelectInput(
session,
inputId = "sel_cat",
choices = levels(as.factor(dplyr::pull(data1(), input$pred_var))),
selected = levels(as.factor(dplyr::pull(data1(), input$pred_var)))
choices = levels(as.factor(data1()[[input$pred_var]])),
selected = levels(as.factor(data1()[[input$pred_var]]))
)

})
Expand All @@ -370,9 +372,7 @@ rbinFactorAddin <- function(data = NULL) {
})

down_bins <- shiny::reactive({
woe_man() %>%
magrittr::use_series(bins) %>%
dplyr::select(level, bin_count, good, bad, woe, iv)
woe_man()$bins[c('level', 'bin_count', 'good', 'bad', 'woe', 'iv')]
})

woe_plot <- shiny::eventReactive(input$create_bins, {
Expand Down
39 changes: 11 additions & 28 deletions R/rbin-create-bins.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,15 @@
#'
rbin_create <- function(data, predictor, bins) {

pred <- rlang::enquo(predictor)

pred_name <-
data %>%
dplyr::select(!! pred) %>%
names()

data2 <-
data %>%
dplyr::select(predictor = !! pred)
pred <- deparse(substitute(predictor))
data2 <- data[pred]
colnames(data2) <- c("predictor")

l_freq <- bins$lower_cut
u_freq <- bins$upper_cut
bin_na <- sum(is.na(bins$bins$bin))
lbins <- length(bins$bins$bin) - bin_na

data2$binned <- NA
dummy_names <- bins$bins$cut_point

Expand All @@ -40,23 +33,13 @@ rbin_create <- function(data, predictor, bins) {
dummy_names[i]
}

bm_rec <- recipes::recipe( ~ ., data = data2)

binned_data <-
bm_rec %>%
recipes::step_dummy(binned) %>%
recipes::prep(training = data2, retain = TRUE) %>%
recipes::bake(new_data = data2)

bin_names <- f_bin(u_freq)[-1]
sym_sign <- c(rep("_<_", (lbins - 2)), "_>=_")

final_data <-
binned_data %>%
dplyr::select(-predictor) %>%
magrittr::set_colnames(paste0(rep(pred_name, (lbins - 2)), sym_sign, bin_names))

dplyr::bind_cols(data, final_data)
data2$binned <- as.factor(data2$binned)
result <- rbin_factor_create(data2, binned)
result[c('predictor', 'binned')] <- NULL
bin_names <- f_bin(u_freq)
sym_sign <- c(rep("_<_", (lbins - 1)), "_>=_")
colnames(result) <- paste0(rep(pred, (lbins - 1)), sym_sign, bin_names)
cbind(data, result)

}

Loading

0 comments on commit ea92edb

Please sign in to comment.