-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.R
39 lines (37 loc) · 1.51 KB
/
functions.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
load_data <- function(file_path, sheet = 1, na_strings = c("NA", "-99", "0", "000")) {
if (endsWith(file_path, ".xls") | endsWith(file_path, ".xlsx")) {
raw_data <- readxl::read_excel(path = file_path,
col_names = TRUE,
na = na_strings,
sheet = sheet)
} else if (endsWith(file_path, ".ods")) {
raw_data <- readODS::read_ods(path = file_path,
col_names = TRUE,
na = na_strings,
sheet = sheet)
} else if (endsWith(file_path, ".tsv") |
endsWith(file_path, ".tdf") |
endsWith(file_path, ".txt")) {
raw_data <- read.table(file = file_path,
header = TRUE,
na.strings = na_strings,
sep = "\t",
stringsAsFactors = FALSE)
} else {
raw_data <- read.table(file = file_path,
header = TRUE,
na.strings = na_strings,
sep = ",",
stringsAsFactors = FALSE)
}
data.frame(raw_data)
}
create_output <- function(res) {
dt <- res
xy <- st_coordinates(dt)
yx <- xy[,2:1]
dt <- st_set_geometry(dt, NULL)
yx <- cbind(dt[,1], yx)
colnames(yx) <- c("Name", "Latitude", "Longitude")
data.frame(yx)
}