From 712ec90bc9596f6dee3147553efe5c93df777bbd Mon Sep 17 00:00:00 2001 From: Ruben Perez Perez Date: Thu, 27 Jul 2023 10:13:35 +0200 Subject: [PATCH] remove deprecated code, fix: https to http for emof join to work --- R/checkdataset.R | 23 ++++++++++++++--------- R/smallfunctions.R | 5 +++-- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/R/checkdataset.R b/R/checkdataset.R index 75de835..09a4b26 100644 --- a/R/checkdataset.R +++ b/R/checkdataset.R @@ -57,6 +57,8 @@ checkdataset = function(Event = NULL, Occurrence = NULL, eMoF = NULL, IPTreport if ( exists("Occurrence") == TRUE ) { + if (!is.null(Occurrence)){ + if(!"occurrenceID" %in% names(Occurrence) & "id" %in% names(Occurrence)) { warning("There is no occurrenceID field in the Occurrence table; occurrenceID created from id field") Occurrence <- Occurrence %>% mutate(occurrenceID = id) @@ -64,7 +66,7 @@ checkdataset = function(Event = NULL, Occurrence = NULL, eMoF = NULL, IPTreport Occurrence <- Occurrence %>% cleandataframe() - } + }} # Occurrence <- Occurrence %>% mutate_all(na_if, 'NA') %>% # mutate_all(na_if, '') %>% @@ -110,16 +112,19 @@ checkdataset = function(Event = NULL, Occurrence = NULL, eMoF = NULL, IPTreport eMoF <- eMoF %>% cleandataframe() - # eMoF <- eMoF %>% mutate_all(na_if, 'NA') %>% - # mutate_all(na_if, '') %>% - # mutate_all(na_if, ' ') - # eMoF <- eMoF[,colSums(is.na(eMoF))% mutate (measurementTypeID = if_else(str_sub(measurementTypeID, -1, -1)=='/',measurementTypeID, paste(measurementTypeID, "/", sep = '')), + measurementValueID = if_else(str_sub(measurementValueID, -1, -1)=='/',measurementValueID, paste(measurementValueID, "/", sep = '')), + measurementUnitID = if_else(str_sub(measurementUnitID, -1, -1)=='/',measurementUnitID, paste(measurementUnitID, "/", sep = '')), + measurementTypeID = str_replace(measurementTypeID, "https://", "http://"), + measurementValueID = str_replace(measurementValueID, "https://", "http://"), + measurementUnitID = str_replace(measurementUnitID, "https://", "http://") + + ) - eMoF <- eMoF %>% mutate (measurementTypeID = if_else(str_sub(measurementTypeID, -1, -1)=='/',measurementTypeID, paste(measurementTypeID, "/", sep = '') ), - measurementValueID = if_else(str_sub(measurementValueID, -1, -1)=='/',measurementValueID, paste(measurementValueID, "/", sep = '')) - ) if ( exists("Event") == TRUE){ if(!is.null(eMoF$eventID) == FALSE){ diff --git a/R/smallfunctions.R b/R/smallfunctions.R index e076870..f3f9675 100644 --- a/R/smallfunctions.R +++ b/R/smallfunctions.R @@ -69,18 +69,19 @@ leftfrom <- function(x, y, n = 0) { cleandataframe <- function (x, vector = TRUE) { + # format to ISO 8601 if class POSIXct for (field in colnames(x)){ if(TRUE %in% (class(x[[field]]) == "POSIXct")){ x[[field]] <- format_iso_8601(x[[field]]) } - # format to ISO 8601 if class POSIXct } + # turn character NAs and spaces into an actual empty cell x <- x %>% mutate(across(where(is.character), ~na_if(., "NA"))) %>% mutate(across(where(is.character), ~na_if(., ""))) %>% mutate(across(where(is.character), ~na_if(., " "))) - + # remove empty columns x <- x[,colSums(is.na(x))