This repository was archived by the owner on Sep 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.R
More file actions
64 lines (60 loc) · 1.4 KB
/
helper.R
File metadata and controls
64 lines (60 loc) · 1.4 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
makeTidyData <- function(tmppath, counter, n) {
tmp <- read_csv(tmppath, quote = "") %>%
distinct()
validate(
need(str_detect((names(tmp)[1]), "Spectrum"), message = "No valid Avaatech XRF baxil batch file (csv)")
)
names(tmp) <- names(tmp) %>%
str_replace_all('\\"', "") %>%
str_trim()
tmp2 <- str_split_fixed(tmp$Spectrum, "\\!", 17) %>%
as_tibble()
names(tmp2) <-
c(
"CoreID",
"unknown1",
"unknown2",
"Depth",
"Date",
"Time",
"Duration",
"Voltage",
"Current",
"unknown3",
"unknown4",
"Filter",
"SlitDown",
"SlitCross",
"Run",
"Rep",
"unknown5"
)
tmp3 <- bind_cols(tmp2, tmp) %>%
select(-starts_with("unknown"),
-Spectrum,
-`Live time`,
-`Real time`,
-Sample,
-User) %>%
mutate_at(
vars(
Depth,
Voltage,
Current,
SlitDown,
SlitCross,
Duration,
Throughput
),
as.numeric
) %>%
mutate(Depth = Depth - min(Depth) + 1) %>%
gather(-(CoreID:Throughput), key = "Measure", value = "Value") %>%
filter(!str_detect(Measure, "Coh"),!str_detect(Measure, "Inc")) %>%
separate(Measure,
sep = "[\\W]+",
into = c("Element", "AbsLine", "Stat")) %>%
spread(Stat, Value)
setProgress(counter / n)
tmp3
}