Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use list2DF() instead of as.data.frame(do.call(cbind...))) #28

Merged
merged 5 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ jobs:
- {os: ubuntu-latest, r: '4.2'}
- {os: ubuntu-latest, r: '4.1'}
- {os: ubuntu-latest, r: '4.0'}
- {os: ubuntu-latest, r: '3.6'}

env:
LANG: ${{ matrix.config.lang }}
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Description: Parse various reflectance/transmittance/absorbance spectra file
<https://www.microspectra.com/>, and 'OceanInsight' (formerly 'OceanOptics')
<https://www.oceaninsight.com/> brands.
Depends:
R (>= 3.6.0)
R (>= 4.0.0)
Imports:
future.apply,
progressr,
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# lightr (development version)

## Minor changes

* lightr now depends on R >= 4.0.0, following the tidyverse recommendation

# lightr 1.7.1

## Internal changes
Expand Down
22 changes: 12 additions & 10 deletions R/get_spec.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,7 @@ lr_get_spec <- function(where = getwd(), ext = "txt", lim = c(300, 700),

message(nb_files, " files found; importing spectra:")

if (!interpolate) {
gsp <- function(f) {
dispatch_parser(f, decimal = decimal, sep = sep)[[1]]
}
} else {
if (interpolate) {
gsp <- function(f) {
df <- dispatch_parser(f, decimal = decimal, sep = sep)[[1]]

Expand All @@ -98,12 +94,15 @@ lr_get_spec <- function(where = getwd(), ext = "txt", lim = c(300, 700),
call. = FALSE)
return(NULL)
}

df <- df[c(min(bounds) - 1, bounds, max(bounds) + 1), ]

approx(df[, "wl"], df[, "processed"],
xout = range, ties = "ordered")$y
}
} else {
gsp <- function(f) {
dispatch_parser(f, decimal = decimal, sep = sep)[[1]]
}
}

with_progress({
Expand Down Expand Up @@ -139,18 +138,21 @@ lr_get_spec <- function(where = getwd(), ext = "txt", lim = c(300, 700),
if (interpolate) {
# We convert to data.frame before adding the wl to preserve wl class (int or
# altrep)
tmp <- as.data.frame(do.call(cbind, tmp))

# Errors have created NULL elements that we need to remove
tmp <- tmp[lengths(tmp) != 0]
tmp <- list2DF(tmp)

final <- cbind(range, tmp)
} else {
if (length(unique(lapply(tmp, function(x) x[, "wl"]))) != 1) {
stop("'interpolate = FALSE' can only work if all input files sample the ",
"same wavelengths.", call. = FALSE)
}
final <- as.data.frame(
do.call(cbind, lapply(tmp, function(x) x[, "processed"]))
)

# Errors have created NULL elements that we need to remove
tmp <- tmp[lengths(tmp) != 0]
final <- list2DF(lapply(tmp, function(x) x[, "processed"]))
final <- cbind(tmp[[1]][, "wl"], final)

# This steps needs to be only run when !interp because it breaks altrep
Expand Down
2 changes: 1 addition & 1 deletion inst/WORDLIST
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
AvaSoft
Avantes
CMD
CRAIC
Chiarenza
DRK
Expand Down Expand Up @@ -53,6 +52,7 @@ noLD
pavo's
rOpenSci
rOpenSci's
tidyverse
timezone
timezones
un
Expand Down
Loading