@@ -49,7 +49,9 @@ vms_clean <- function(path_to_data) {
4949" speed" ,
5050" direction"
5151 )
52-
52+ empty_coordinates <- x | >
53+ dplyr :: filter(is.na(.data $ latitude ))| >
54+ dplyr :: filter(is.na(.data $ longitude ))
5355res <- x | >
5456dplyr :: mutate(date = as.POSIXct(date ,format = " %d/%m/%Y %H:%M" ,tz = " UTC" ))| >
5557dplyr :: mutate(year = lubridate :: year(date ))| >
@@ -64,11 +66,9 @@ vms_clean <- function(path_to_data) {
6466dplyr :: filter(! is.na(.data $ speed ))| >
6567dplyr :: mutate(file_name = stringr :: str_remove(path_to_data ," data/VMS-data/raw//" ))
6668
67- empty_coordinates <- x | >
68- dplyr :: filter(is.na(.data $ latitude ))| >
69- dplyr :: filter(is.na(.data $ longitude ))
70- message(paste0(" Cleaned:" , print(nrow(empty_coordinates ))," empty rows from data!\n " ))
71- res
69+
70+ message(paste0(" Cleaned:" , (nrow(empty_coordinates ))," empty rows from data!\n " ))
71+
7272 }else if (is.data.frame(path_to_data )== TRUE ) {
7373x <- path_to_data
7474
@@ -83,6 +83,13 @@ vms_clean <- function(path_to_data) {
8383" speed" ,
8484" direction"
8585 )
86+ empty_coordinates <- x | >
87+ dplyr :: mutate(
88+ latitude = as.numeric(.data $ latitude ),
89+ longitude = as.numeric(.data $ longitude )
90+ )| >
91+ dplyr :: filter(is.na(.data $ latitude ))| >
92+ dplyr :: filter(is.na(.data $ longitude ))
8693
8794res <- x | >
8895dplyr :: mutate(date = as.POSIXct(date ,format = " %d/%m/%Y %H:%M" ,tz = " UTC" ))| >
@@ -100,15 +107,9 @@ vms_clean <- function(path_to_data) {
100107dplyr :: mutate(direction = as.numeric(.data $ direction ))| >
101108dplyr :: mutate(speed = as.numeric(.data $ speed ))
102109
103- empty_coordinates <- x | >
104- dplyr :: mutate(
105- latitude = as.numeric(.data $ latitude ),
106- longitude = as.numeric(.data $ longitude )
107- )| >
108- dplyr :: filter(is.na(.data $ latitude ))| >
109- dplyr :: filter(is.na(.data $ longitude ))
110- message(paste0(" Cleaned:" , print(nrow(empty_coordinates ))," empty rows from data!\n " ))
111- res
110+ message(paste0(" Cleaned:" , (nrow(empty_coordinates ))," empty rows from data!\n " ))
111+
112+
112113 }else {
113114 stop(" Data must be a path to folder or data.frame object\n " )
114115 }