10 #### Read in raw JSON ####
12 # 1. Input JSON filepath
13 # 2. Output filepath for .png plot of spectra
15 args <- commandArgs(trailingOnly = TRUE)
17 raw.spectra <- jsonlite::fromJSON(txt = args[1], flatten = T) %>%
18 type_convert(cols(.default = col_double(), observationUnitId = col_character(),
19 device_type = col_character())) %>%
20 dplyr::select(observationUnitId, device_type, starts_with("nirs_spectra"))
22 wls <- colnames(raw.spectra) %>%
23 str_subset("nirs_spectra.") %>%
24 str_remove("nirs_spectra.") %>%
25 readr::parse_number() %>%
28 raw.spectra <- raw.spectra %>%
29 dplyr::select(observationUnitId, device_type, paste0("nirs_spectra.X", wls))
31 #### Generate plot and identify outliers ####
32 spec.plot <- raw.spectra %>%
33 rename_at(vars(starts_with("nirs_spectra")), ~str_replace(., "nirs_spectra.", "")) %>%
34 rownames_to_column(var = "unique.id") %>%
35 dplyr::select(-device_type) %>%
36 plot_spectra(wls, num.col.before.spectra = 3, window.size = 100)
39 ggsave(plot = spec.plot, filename = args[2], units = "in", height = 7, width = 10)