diff --git a/DESCRIPTION b/DESCRIPTION index b0f7745..6b5507a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -9,3 +9,7 @@ License: MIT + file LICENSE Encoding: UTF-8 Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.1 +Imports: + dplyr (>= 1.1.4), + magrittr (>= 2.0.3), + rlang (>= 1.1.3) 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/check.R b/R/check.R new file mode 100644 index 0000000..4540389 --- /dev/null +++ b/R/check.R @@ -0,0 +1,19 @@ +#' Check +#' +#' @author Sander Devisscher +#' +#' @description +#' Helper script to determine existence in environment panel +#' +#' @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)) && ifelse(is.function(x), stop(), 0)) 1 else 1, error=function(e) 0)} diff --git a/R/colcompare.R b/R/colcompare.R new file mode 100644 index 0000000..0465af8 --- /dev/null +++ b/R/colcompare.R @@ -0,0 +1,85 @@ +#' Columnname comparison +#' +#' @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 +#' \dontrun{ +#' # 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) +#' } +#' +#' @importFrom magrittr %>% + +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(!rlang::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(!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) + print("=====================================================================") + } + } + + # Only y #### + test_yinx <- combined %>% + dplyr::filter(is.na(test_xiny)) + test_yinx <- test_yinx$test_yinx + + if(check(test_yinx)==1){ + 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/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/check.Rd b/man/check.Rd new file mode 100644 index 0000000..dab806f --- /dev/null +++ b/man/check.Rd @@ -0,0 +1,24 @@ +% 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 environment +0 = object doesn't exist in environment +} +\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 +} diff --git a/man/colcompare.Rd b/man/colcompare.Rd new file mode 100644 index 0000000..24ec9f3 --- /dev/null +++ b/man/colcompare.Rd @@ -0,0 +1,40 @@ +% 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{ +\dontrun{ +# 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 +} diff --git a/man/scafold.txt b/man/scafold.txt deleted file mode 100644 index e69de29..0000000 diff --git a/src/scafold.txt b/src/scafold.txt deleted file mode 100644 index e69de29..0000000