From b7f891b04103589a047adae5a0e142e768a811a8 Mon Sep 17 00:00:00 2001 From: Sander Devisscher Date: Mon, 29 Apr 2024 16:17:55 +0200 Subject: [PATCH 01/11] create colcompare #7 --- R/check.R | 13 ++++++++ R/colcompare.R | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ R/scafold.txt | 0 data/scafold.txt | 0 man/scafold.txt | 0 5 files changed, 92 insertions(+) create mode 100644 R/check.R create mode 100644 R/colcompare.R delete mode 100644 R/scafold.txt delete mode 100644 data/scafold.txt delete mode 100644 man/scafold.txt diff --git a/R/check.R b/R/check.R new file mode 100644 index 0000000..69acf4c --- /dev/null +++ b/R/check.R @@ -0,0 +1,13 @@ +#' @author Sander Devisscher +#' +#' @description +#' Helper script to determine existance in environment panel +#' +#' @param x environment object +#' +#' @returns +#' 1 = object exists in enviroment +#' 0 = object doesn't exist in enviroment + + +check <- function(x){tryCatch(if(class(x) == 'logical') 1 else 1, error=function(e) 0)} diff --git a/R/colcompare.R b/R/colcompare.R new file mode 100644 index 0000000..4a4d81d --- /dev/null +++ b/R/colcompare.R @@ -0,0 +1,79 @@ +#' @author Sander Devisscher +#' +#' @description +#' A simple function to list the difference in column names in 2 datasets. +#' +#' @param x dataframe 1 +#' @param y dataframe 2 +#' +#' @return +#' a list of columns present in x but not in y and a list of columns +#' present in y and not in x. +#' +#' @examples +#' # create example dataframes +#' super_sleepers <- data.frame(rating=1:4, +#' animal=c('koala', 'hedgehog', 'sloth', 'panda'), +#' country=c('Australia', 'Italy', 'Peru', 'China'), +#' avg_sleep_hours=c(21, 18, 17, 10)) +#' +#' super_actives <- data.frame(rating=1:4, +#' animal=c('kangeroo', 'wolf', 'jaguar', 'tiger'), +#' country=c('Australia', 'Italy', 'Peru', 'China'), +#' avg_active_hours=c(16, 15, 8, 10))) +#' +#' colcompare(super_sleepers, super_actives) + +colcompare <- function(x, y){ + + test_xiny <- subset(colnames(x), !colnames(x) %in% colnames(y)) + test_xiny <- as.data.frame(test_xiny) %>% + dplyr::mutate(lower = tolower(test_xiny)) + test_yinx <- subset(colnames(y), !colnames(y) %in% colnames(x)) + test_yinx <- as.data.frame(test_yinx) %>% + dplyr::mutate(lower = tolower(test_yinx)) + + combined <- test_xiny %>% + dplyr::full_join(test_yinx, by = "lower") + + # Typos (x en y) #### + test_xANDy <- combined %>% + dplyr::filter(!is.na(test_xiny) & !is.na(test_yinx)) %>% + dplyr::mutate(test_xANDy = paste0("X: ", test_xiny, " <==> ", test_yinx, " :Y \n")) + test_xANDy <- test_xANDy$test_xANDy + + if(check(test_xANDy) == 1){ + if(!is_empty(test_xANDy)){ + error <- paste0("Kolommen met verschillende schrijfwijze: \n", + test_xANDy) + writeLines(error) + print("=====================================================================") + } + } + # Only X #### + test_xiny <- combined %>% + dplyr::filter(is.na(test_yinx)) + test_xiny <- test_xiny$test_xiny + + if(check(test_xiny)==1){ + if(!is_empty(test_xiny)){ + test_xiny <- paste(test_xiny, collapse = ", \n") + error <- paste0("Kolommen uit x die niet in y voorkomen: \n", test_xiny) + writeLines(error) + print("=====================================================================") + } + } + + # Only y #### + test_yinx <- combined %>% + dplyr::filter(is.na(test_xiny)) + test_yinx <- test_yinx$test_yinx + + if(check(test_yinx)==1){ + if(!is_empty(test_yinx)){ + test_yinx <- paste(test_yinx, collapse = ", \n") + error <- paste0("Kolommen uit y die niet in x voorkomen: ", test_yinx) + writeLines(error) + } + } +} diff --git a/R/scafold.txt b/R/scafold.txt deleted file mode 100644 index e69de29..0000000 diff --git a/data/scafold.txt b/data/scafold.txt deleted file mode 100644 index e69de29..0000000 diff --git a/man/scafold.txt b/man/scafold.txt deleted file mode 100644 index e69de29..0000000 From c4ee29c5209e6e8fdd2ef02ef1505611775eb268 Mon Sep 17 00:00:00 2001 From: Sander Devisscher Date: Mon, 29 Apr 2024 16:19:25 +0200 Subject: [PATCH 02/11] Create rds #7 --- R/check.R | 2 ++ R/colcompare.R | 2 ++ man/check.Rd | 21 +++++++++++++++++++++ man/colcompare.Rd | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+) create mode 100644 man/check.Rd create mode 100644 man/colcompare.Rd diff --git a/R/check.R b/R/check.R index 69acf4c..4611414 100644 --- a/R/check.R +++ b/R/check.R @@ -1,3 +1,5 @@ +#' Check +#' #' @author Sander Devisscher #' #' @description diff --git a/R/colcompare.R b/R/colcompare.R index 4a4d81d..d18b348 100644 --- a/R/colcompare.R +++ b/R/colcompare.R @@ -1,3 +1,5 @@ +#' Columnname comparison +#' #' @author Sander Devisscher #' #' @description diff --git a/man/check.Rd b/man/check.Rd new file mode 100644 index 0000000..011f520 --- /dev/null +++ b/man/check.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/check.R +\name{check} +\alias{check} +\title{Check} +\usage{ +check(x) +} +\arguments{ +\item{x}{environment object} +} +\value{ +1 = object exists in enviroment +0 = object doesn't exist in enviroment +} +\description{ +Helper script to determine existance in environment panel +} +\author{ +Sander Devisscher +} diff --git a/man/colcompare.Rd b/man/colcompare.Rd new file mode 100644 index 0000000..4bf6861 --- /dev/null +++ b/man/colcompare.Rd @@ -0,0 +1,37 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/colcompare.R +\name{colcompare} +\alias{colcompare} +\title{Columnname comparison} +\usage{ +colcompare(x, y) +} +\arguments{ +\item{x}{dataframe 1} + +\item{y}{dataframe 2} +} +\value{ +a list of columns present in x but not in y and a list of columns +present in y and not in x. +} +\description{ +A simple function to list the difference in column names in 2 datasets. +} +\examples{ +# create example dataframes +super_sleepers <- data.frame(rating=1:4, +animal=c('koala', 'hedgehog', 'sloth', 'panda'), +country=c('Australia', 'Italy', 'Peru', 'China'), +avg_sleep_hours=c(21, 18, 17, 10)) + +super_actives <- data.frame(rating=1:4, +animal=c('kangeroo', 'wolf', 'jaguar', 'tiger'), +country=c('Australia', 'Italy', 'Peru', 'China'), +avg_active_hours=c(16, 15, 8, 10))) + +colcompare(super_sleepers, super_actives) +} +\author{ +Sander Devisscher +} From 8f37cff528ece5bc5e508ebab67d51c086cbeec1 Mon Sep 17 00:00:00 2001 From: Sander Devisscher Date: Mon, 29 Apr 2024 16:23:20 +0200 Subject: [PATCH 03/11] Delete scafold.txt #7 --- src/scafold.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/scafold.txt diff --git a/src/scafold.txt b/src/scafold.txt deleted file mode 100644 index e69de29..0000000 From 21f0e4935e2d3c008bdff6ad028dc9ffc4302986 Mon Sep 17 00:00:00 2001 From: Sander Devisscher Date: Mon, 29 Apr 2024 16:27:07 +0200 Subject: [PATCH 04/11] Update DESCRIPTION #7 --- DESCRIPTION | 3 +++ 1 file changed, 3 insertions(+) diff --git a/DESCRIPTION b/DESCRIPTION index b0f7745..f31705a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -9,3 +9,6 @@ License: MIT + file LICENSE Encoding: UTF-8 Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.1 +Imports: + dplyr (>= 1.1.4), + magrittr (>= 2.0.3) From 4e684d6ff3716730a9a7ab91826d63e28cee7234 Mon Sep 17 00:00:00 2001 From: Sander Devisscher Date: Mon, 29 Apr 2024 16:28:12 +0200 Subject: [PATCH 05/11] update function #7 --- NAMESPACE | 1 + R/colcompare.R | 2 ++ man/colcompare.Rd | 1 + 3 files changed, 4 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index 6ae9268..0b03a8f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,2 +1,3 @@ # Generated by roxygen2: do not edit by hand +importFrom(magrittr,"%>%") diff --git a/R/colcompare.R b/R/colcompare.R index d18b348..7ad8eb5 100644 --- a/R/colcompare.R +++ b/R/colcompare.R @@ -25,6 +25,8 @@ #' avg_active_hours=c(16, 15, 8, 10))) #' #' colcompare(super_sleepers, super_actives) +#' +#' @importFrom magrittr %>% colcompare <- function(x, y){ diff --git a/man/colcompare.Rd b/man/colcompare.Rd index 4bf6861..89266ac 100644 --- a/man/colcompare.Rd +++ b/man/colcompare.Rd @@ -31,6 +31,7 @@ country=c('Australia', 'Italy', 'Peru', 'China'), avg_active_hours=c(16, 15, 8, 10))) colcompare(super_sleepers, super_actives) + } \author{ Sander Devisscher From 7544f08a9039a491d7f2d08dd253a713eea38674 Mon Sep 17 00:00:00 2001 From: Sander Devisscher Date: Tue, 30 Apr 2024 09:47:54 +0200 Subject: [PATCH 06/11] fix remaining errors & warnings #7 --- DESCRIPTION | 3 ++- R/check.R | 2 +- R/colcompare.R | 10 ++++++---- man/colcompare.Rd | 4 +++- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f31705a..6b5507a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -11,4 +11,5 @@ Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.1 Imports: dplyr (>= 1.1.4), - magrittr (>= 2.0.3) + magrittr (>= 2.0.3), + rlang (>= 1.1.3) diff --git a/R/check.R b/R/check.R index 4611414..46a952f 100644 --- a/R/check.R +++ b/R/check.R @@ -12,4 +12,4 @@ #' 0 = object doesn't exist in enviroment -check <- function(x){tryCatch(if(class(x) == 'logical') 1 else 1, error=function(e) 0)} +check <- function(x){tryCatch(if(is.logical(class(x))) 1 else 1, error=function(e) 0)} diff --git a/R/colcompare.R b/R/colcompare.R index 7ad8eb5..0465af8 100644 --- a/R/colcompare.R +++ b/R/colcompare.R @@ -13,6 +13,7 @@ #' present in y and not in x. #' #' @examples +#' \dontrun{ #' # create example dataframes #' super_sleepers <- data.frame(rating=1:4, #' animal=c('koala', 'hedgehog', 'sloth', 'panda'), @@ -22,9 +23,10 @@ #' super_actives <- data.frame(rating=1:4, #' animal=c('kangeroo', 'wolf', 'jaguar', 'tiger'), #' country=c('Australia', 'Italy', 'Peru', 'China'), -#' avg_active_hours=c(16, 15, 8, 10))) +#' avg_active_hours=c(16, 15, 8, 10)) #' #' colcompare(super_sleepers, super_actives) +#' } #' #' @importFrom magrittr %>% @@ -47,7 +49,7 @@ colcompare <- function(x, y){ test_xANDy <- test_xANDy$test_xANDy if(check(test_xANDy) == 1){ - if(!is_empty(test_xANDy)){ + if(!rlang::is_empty(test_xANDy)){ error <- paste0("Kolommen met verschillende schrijfwijze: \n", test_xANDy) writeLines(error) @@ -60,7 +62,7 @@ colcompare <- function(x, y){ test_xiny <- test_xiny$test_xiny if(check(test_xiny)==1){ - if(!is_empty(test_xiny)){ + if(!rlang::is_empty(test_xiny)){ test_xiny <- paste(test_xiny, collapse = ", \n") error <- paste0("Kolommen uit x die niet in y voorkomen: \n", test_xiny) writeLines(error) @@ -74,7 +76,7 @@ colcompare <- function(x, y){ test_yinx <- test_yinx$test_yinx if(check(test_yinx)==1){ - if(!is_empty(test_yinx)){ + if(!rlang::is_empty(test_yinx)){ test_yinx <- paste(test_yinx, collapse = ", \n") error <- paste0("Kolommen uit y die niet in x voorkomen: ", test_yinx) writeLines(error) diff --git a/man/colcompare.Rd b/man/colcompare.Rd index 89266ac..24ec9f3 100644 --- a/man/colcompare.Rd +++ b/man/colcompare.Rd @@ -19,6 +19,7 @@ present in y and not in x. A simple function to list the difference in column names in 2 datasets. } \examples{ +\dontrun{ # create example dataframes super_sleepers <- data.frame(rating=1:4, animal=c('koala', 'hedgehog', 'sloth', 'panda'), @@ -28,9 +29,10 @@ avg_sleep_hours=c(21, 18, 17, 10)) super_actives <- data.frame(rating=1:4, animal=c('kangeroo', 'wolf', 'jaguar', 'tiger'), country=c('Australia', 'Italy', 'Peru', 'China'), -avg_active_hours=c(16, 15, 8, 10))) +avg_active_hours=c(16, 15, 8, 10)) colcompare(super_sleepers, super_actives) +} } \author{ From fd41321952167b60a48999cb9f7f121db14de17e Mon Sep 17 00:00:00 2001 From: soriadelva Date: Tue, 30 Apr 2024 11:37:58 +0200 Subject: [PATCH 07/11] Update check.R --- R/check.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/check.R b/R/check.R index 46a952f..fe6bde3 100644 --- a/R/check.R +++ b/R/check.R @@ -3,13 +3,13 @@ #' @author Sander Devisscher #' #' @description -#' Helper script to determine existance in environment panel +#' Helper script to determine existence in environment panel #' #' @param x environment object #' #' @returns -#' 1 = object exists in enviroment -#' 0 = object doesn't exist in enviroment +#' 1 = object exists in environment +#' 0 = object doesn't exist in environment check <- function(x){tryCatch(if(is.logical(class(x))) 1 else 1, error=function(e) 0)} From 16c63255f74845fd0599f3050ef70e426a4e6068 Mon Sep 17 00:00:00 2001 From: Sander Devisscher Date: Tue, 30 Apr 2024 13:38:57 +0200 Subject: [PATCH 08/11] fix check #7 I forgot to invert test :stuck_out_tongue_winking_eye: --- R/check.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/check.R b/R/check.R index fe6bde3..377b659 100644 --- a/R/check.R +++ b/R/check.R @@ -12,4 +12,4 @@ #' 0 = object doesn't exist in environment -check <- function(x){tryCatch(if(is.logical(class(x))) 1 else 1, error=function(e) 0)} +check <- function(x){tryCatch(if(!is.logical(class(x))) 1 else 1, error=function(e) 0)} From 66e601f95a2569ac9583a14705913ba9f7557646 Mon Sep 17 00:00:00 2001 From: Sander Devisscher Date: Tue, 30 Apr 2024 13:41:12 +0200 Subject: [PATCH 09/11] Update check.Rd #7 @soriadelva running devtools::check() updates the relevant .rd files --- man/check.Rd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/man/check.Rd b/man/check.Rd index 011f520..7edb726 100644 --- a/man/check.Rd +++ b/man/check.Rd @@ -10,11 +10,11 @@ check(x) \item{x}{environment object} } \value{ -1 = object exists in enviroment -0 = object doesn't exist in enviroment +1 = object exists in environment +0 = object doesn't exist in environment } \description{ -Helper script to determine existance in environment panel +Helper script to determine existence in environment panel } \author{ Sander Devisscher From 37778b1d9e32aa51c1906b8ce35a08b99b82e0f9 Mon Sep 17 00:00:00 2001 From: Sander Devisscher Date: Tue, 30 Apr 2024 16:02:35 +0200 Subject: [PATCH 10/11] Update check.R #7 --- R/check.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/check.R b/R/check.R index 377b659..4540389 100644 --- a/R/check.R +++ b/R/check.R @@ -7,9 +7,13 @@ #' #' @param x environment object #' +#' @details +#' This doesn't work with functions which will yield a 0 by default. +#' +#' #' @returns #' 1 = object exists in environment #' 0 = object doesn't exist in environment -check <- function(x){tryCatch(if(!is.logical(class(x))) 1 else 1, error=function(e) 0)} +check <- function(x){tryCatch(if(!is.logical(class(x)) && ifelse(is.function(x), stop(), 0)) 1 else 1, error=function(e) 0)} From efcb1f6ff58d16e88ab485d38f24de2354aeef61 Mon Sep 17 00:00:00 2001 From: Sander Devisscher Date: Tue, 30 Apr 2024 16:02:44 +0200 Subject: [PATCH 11/11] Update check.Rd #7 --- man/check.Rd | 3 +++ 1 file changed, 3 insertions(+) diff --git a/man/check.Rd b/man/check.Rd index 7edb726..dab806f 100644 --- a/man/check.Rd +++ b/man/check.Rd @@ -16,6 +16,9 @@ check(x) \description{ Helper script to determine existence in environment panel } +\details{ +This doesn't work with functions which will yield a 0 by default. +} \author{ Sander Devisscher }