Skip to content

Commit

Permalink
v0.1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
yh202109 committed Oct 20, 2022
1 parent cbacf06 commit cf78b1d
Show file tree
Hide file tree
Showing 48 changed files with 326 additions and 56 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.Rproj.user
.Rbuildignore
.Rprofile
cran-comments.md
.Rhistory
.RData
.Ruserdata
Expand All @@ -11,6 +10,11 @@ inst/doc
/doc/
/Meta/
vignettes/.gitignore
.github/.gitignore
.gitignore
.github
mtb.Rproj
CRAN-RELEASE
CRAN-SUBMISSION
_pkgdown.yml
cran-comments.md
3 changes: 0 additions & 3 deletions CRAN-SUBMISSION

This file was deleted.

2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: mtb
Type: Package
Title: My Toolbox for Assisting Document Editing and Data Presenting
Version: 0.1.7
Version: 0.1.8
Authors@R: c(
person("Y", "Hsu", email="[email protected]", role=c('aut','cre'))
)
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export(add_colored_box)
export(add_colored_str)
export(bill_cross_check)
export(bill_cross_count)
export(color_set_palette)
export(color_test_palette)
Expand Down
10 changes: 8 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# mtb 0.1.7 (commit `TBA`)
# mtb 0.1.8 (commit `TBA`)

## Major changes

* bill - add comparison between 2 tables

# mtb 0.1.7 (commit `cbacf062`)

## Major changes

* text - add length restriction option
* text - add functions for name, address, and slashes
* bill - add cross comparison between multiple bill table
* bill - add cross-count between multiple bill tables

# mtb 0.1.6 (commit `d7b8929`)

Expand Down
64 changes: 62 additions & 2 deletions R/helper_bill_crosscompare.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ utils::globalVariables(c("."))
#' Summarize times being purchased for individual items'
#' from multiple grocery shopping lists.
#'
#' \code{bill_summary} returns a data.table showing how many times each
#' \code{bill_cross_count} returns a data.table showing how many times each
#' items being listed on individual bills.
#'
#' @import data.table
#'
#' @param ldt A list of grocery tables in data.frame format.
#' @param id A column name
#' @param gp A column name
#' @param gp A column name or a vector of column names
#' @param type A string in one of the following:
#' \itemize{
#' \item \code{count} for number of rows in each bill
Expand Down Expand Up @@ -83,6 +83,66 @@ bill_cross_count <- function(ldt=list(), id=NULL, gp=NULL, type = 'count', conds
out
}

############################################################
#' Check two tables with unique matching ids and generate reports
#' on duplicated ids and repeated columns when applicable..
#'
#' \code{bill_cross_check} returns a merged data.table showing
#' information regarding ids and repeated columns.
#'
#' @import data.table
#'
#' @param dt1 A table.
#' @param dt2 A table.
#' @param id A column name or a vector of column names
#' @param chk A column name
#'
#' @return a data.table
#'
#' @examples
#'
#' bill_cross_check(data.frame(col1=c(1,2,3,3), col2=c('a','b','c','c'),
#' col3=c('-','=','+','-')),data.frame(col1=c(1,2,3), col2=c('a','b','c'),
#' col3=c('-','=','+')), id=c('col1','col2'), chk='col3')
#'
#' @export
#'

bill_cross_check <- function(dt1=NULL, dt2=NULL, id=NULL, chk=NULL ) {
if(is.null(dt1)|is.null(dt2)){stop('dt1 and dt2 should be tables.')}
dt1$row_id = seq(1,nrow(dt1))
dt2$row_id = seq(1,nrow(dt2))
ldt=list(as.data.table(dt1),as.data.table(dt2))
sdt=sapply(ldt,dim)
if(min(apply(sdt,2,min))==0){stop('dt1 and dt2 should be tables')}
if(!is.null(id)){id=as.character(id)}else{stop('id should be a column name')}
if(!is.null(chk)){
chk=as.character(chk)
if(length(chk) == 1){
if(is.na(chk)){stop('chk should be a column name')}
if(!mtb_col_in_ldt(chk, ldt)){stop('chk should be a column name')}
}else{chk=NULL}
}
if(length(id) >= 1){
for(idx in 1:length(id)){
if(is.na(id[idx])){stop('id should be a column name')}
if(!mtb_col_in_ldt(id[idx], ldt)){stop('id should be a column name')}
}
}else{stop('id should be a column name')}
lldt=rbindlist(ldt, idcol='tbl_id', fill=TRUE)
if(is.null(names(ldt))){ lldt$tbl_id=paste0('tbl_id:',lldt$tbl_id) }else{ lldt$tbl_id=paste0('t',lldt$tbl_id,':',names(ldt)) }
cn=(unique(lldt$tbl_id))
if(length(chk) == 1){
out=dcast(lldt[, .(tbl_count=paste(eval(parse(text=chk)), collapse=";")),by=c(id,'tbl_id')], paste(paste(c(id),collapse='+'), '~ tbl_id'), value.var="tbl_count")
}else{
out=dcast(lldt[, .(tbl_count=.N),by=c(id,'tbl_id')], paste(paste(c(id),collapse='+'), '~ tbl_id'), value.var="tbl_count")
}
nc=ncol(out)
out$same=(out[[nc]]==out[[nc-1]])
out
}

############################################################
#' Example dataset
#'
#' @name exdt
Expand Down
8 changes: 0 additions & 8 deletions cran-comments.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/LICENSE.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/articles/mtb_axis.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified docs/articles/mtb_axis_files/figure-html/unnamed-chunk-2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/articles/mtb_axis_files/figure-html/unnamed-chunk-3-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/articles/mtb_axis_files/figure-html/unnamed-chunk-4-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/articles/mtb_axis_files/figure-html/unnamed-chunk-5-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 14 additions & 2 deletions docs/articles/mtb_bill_summary.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/articles/mtb_color.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/articles/mtb_md.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/articles/mtb_timerelated.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions docs/authors.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions docs/news/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ articles:
mtb_color: mtb_color.html
mtb_md: mtb_md.html
mtb_timerelated: mtb_timerelated.html
last_built: 2022-10-12T01:57Z
last_built: 2022-10-20T14:16Z
urls:
reference: https://yh202109.github.io/mtb/reference
article: https://yh202109.github.io/mtb/articles
Expand Down
Binary file modified docs/reference/Rplot001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/reference/add_colored_box.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/add_colored_str.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cf78b1d

Please sign in to comment.