Skip to content

Commit

Permalink
major tidy in preparation for cran
Browse files Browse the repository at this point in the history
  • Loading branch information
coolbutuseless committed Apr 27, 2024
1 parent 32488dc commit 502c18b
Show file tree
Hide file tree
Showing 54 changed files with 1,056 additions and 1,084 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
^data-raw$
^pkgdown$
^\.github$
^LICENSE\.md$
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ inst/doc
doc
Meta
pkgdown
working
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
Package: emphatic
Type: Package
Title: ANSI Colouring of Data.Frames, Matrices and Atomic Vectors
Version: 0.1.5
Title: Exploration of Data.Frames, Matrices using ANSI Colouring
Version: 0.1.6
Author: mikefc
Maintainer: mikefc <[email protected]>
Description: Colour data.frame, matrix and vector output in the console.
URL: https://coolbutuseless.github.io/package/emphatic, https://github.com/coolbutuseless/emphatic
URL: https://coolbutuseless.github.io/package/emphatic/, https://github.com/coolbutuseless/emphatic
BugReports: https://github.com/coolbutuseless/emphatic/issues
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Depends:
R (>= 2.10)
Suggests:
Expand Down
21 changes: 2 additions & 19 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,19 +1,2 @@
Copyright (c) 2020 [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
YEAR: 2023,2024
COPYRIGHT HOLDER: Mike Cheng
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023,2024 [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
12 changes: 3 additions & 9 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@ export(as_emphatic)
export(as_html)
export(as_svg)
export(hl)
export(hl_adjust)
export(hl_diff)
export(hl_grep)
export(hl_grep_character)
export(hl_grep_deparse)
export(hl_grep_print)
export(hl_grep_str)
export(hl_loc)
export(hl_mat)
export(hl_opt)
export(hl_opt_global)
export(hl_str_diff)
export(hl_vec)
export(hl_opts)
export(is_emphatic)
export(knit_print.emphatic)
importFrom(grDevices,col2rgb)
Expand Down
11 changes: 10 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@

# emphatic 0.1.6 2024-04-27

* Consolidated `hl_grep()` variants into single function
* `hl_diff()` now operates on any object
* `hl_vec()` removed
* Setting options has been totally overhauled
* `hl_mat()` now has a `byrow()` argument


# emphatic 0.1.5 2023-08-30

* Added `hl_str_diff()` to highlight differences between two strings.
* Added `hl_diff()` to highlight differences between two strings.
* Added functions for highlighting the results of a `grep()`
* `hl_grep()`
* `hl_str()`
Expand Down
23 changes: 12 additions & 11 deletions R/core.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ is_emphatic <- function(x) {
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#' Print an \code{emphatic} data.frame, matrix or atomic vector
#'
#' @inheritParams hl_opt_global
#' @inheritParams hl_opts
#' @inheritParams as.character.emphatic
#'
#' @export
Expand Down Expand Up @@ -159,14 +159,14 @@ as.character.emphatic <- function(x, ..., mode = 'ansi') {
stopifnot(mode %in% c('ansi', 'html'))

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Remove the 'emphatic' class here, so that if any subsequence operations
# rely on 'as.character()' for this base class, they don't infitiely
# Remove the 'emphatic' class here, so that if any subsequent operations
# rely on 'as.character()' for this base class, they don't infinitely
# call 'as.character.emphatic'
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class(x) <- setdiff(class(x), 'emphatic')

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Co-erce tibbles into data.frames.
# Coerce tibbles into data.frames.
# tibble:::print.tibble() already does some ANSI markup, and in doing so,
# the results of calling "format()" are not the same as calling format()
# on a data.frame.
Expand All @@ -178,10 +178,8 @@ as.character.emphatic <- function(x, ..., mode = 'ansi') {
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Build full options by combining global and local options
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
global_opt <- getOption('emphatic', default = list())
local_opt <- attr(x, 'options', exact = TRUE) %||% list()
opt <- modifyList(default_options, global_opt)
opt <- modifyList(opt, local_opt)
opt <- attr(x, 'options', exact = TRUE) %||% list()
opt <- modifyList(hl_opts(), opt)

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# format the data as character matrix
Expand Down Expand Up @@ -269,7 +267,7 @@ as.character.emphatic <- function(x, ..., mode = 'ansi') {
#' @param text,fill matrices of colours to apply to each given cell.
#' Dimensions must match that of \code{m}
#' @param legends any strings for legends to print. default NULL
#' @inheritParams hl_opt_global
#' @inheritParams hl_opts
#' @inheritParams as.character.emphatic
#' @param atomic was this originally an atomic vector? if so use a slightly
#' different printing method
Expand Down Expand Up @@ -519,7 +517,7 @@ as_character_inner <- function(m,
#' There is a further call to 'interp_colour' in order to control the contrast.
#'
#' @param fill vector of background colours
#' @inheritParams hl_opt_global
#' @inheritParams hl_opts
#'
#' @return contrasting text colour for readable text
#'
Expand Down Expand Up @@ -568,7 +566,10 @@ calc_contrasting_text <- function(fill, text_contrast, dark_mode) {
# If there wasn't an actual fill colour set, then don't set a text colour.
# i.e. this will use the default console colouring
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# text[fill_not_set] <- ''
if (text_contrast == 1) {
# retain original colours
contrast_colour[fill_not_set] <- ''
}

contrast_colour
}
Expand Down
2 changes: 1 addition & 1 deletion R/data-sets.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#'
#' \itemize{
#' \item{\url{http://williamwolff.org/wp-content/uploads/2013/01/tufte-challenger-1997.pdf}}
#' \item{\url{https://archive.ics.uci.edu/ml/datasets/Challenger+USA+Space+Shuttle+O-Ring}}
#' \item{\url{https://archive.ics.uci.edu/dataset/92/challenger+usa+space+shuttle+o+ring}}
#' }
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"challenger"
Expand Down
15 changes: 10 additions & 5 deletions R/data.frame.R → R/hl-dataframe.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#' combinations of the specified rows and columns will be highlighted.
#' Otherwise the locations are
#' created using a simpler call to \code{cbind()}.
#'
#' @export
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hl_loc <- function(.data, colour, row_ids, col_ids, elem = 'fill', major = 'row', expand_grid = TRUE) {

Expand Down Expand Up @@ -233,6 +231,7 @@ hl_inner <- function(.data, colour, row_ids, column, dest_col_ids, elem, show_le
#' @param show_legend if a scale object is used for colour, and \code{show_legend = TRUE},
#' then a colourbar legend will be added to the bottom of the output.
#' Default: FALSE
#' @inheritParams hl_grep
#'
#' @examples
#' \dontrun{
Expand All @@ -242,8 +241,13 @@ hl_inner <- function(.data, colour, row_ids, column, dest_col_ids, elem, show_le
#'
#' @export
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hl <- function(.data, colour, rows = NULL, cols = NULL, dest_cols, calc_scale = 'first', elem = 'fill',
show_legend = FALSE) {
hl <- function(.data, colour,
rows = NULL, cols = NULL,
dest_cols,
calc_scale = 'first',
elem = 'fill',
show_legend = FALSE,
opts = hl_opts()) {

stopifnot(is.data.frame(.data))
stopifnot(elem %in% c('text', 'fill'))
Expand All @@ -259,7 +263,7 @@ hl <- function(.data, colour, rows = NULL, cols = NULL, dest_cols, calc_scale =
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Unpack which rows/columns are being highlighted
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.x <- .data
.x <- .data # used for lookup within loc_expr_to_ids()
col_ids <- loc_expr_to_ids(.data, expr = substitute(cols), axis = 'column')
row_ids <- loc_expr_to_ids(.data, expr = substitute(rows), axis = 'row' )

Expand Down Expand Up @@ -322,6 +326,7 @@ hl <- function(.data, colour, rows = NULL, cols = NULL, dest_cols, calc_scale =
stop("colour not understood: ", deparse(colour))
}

attr(.data, "options") <- opts

.data
}
Expand Down
Loading

0 comments on commit 502c18b

Please sign in to comment.