Skip to content

Commit 961837c

Browse files
committed
Make the export of the component contribution matrix optional.
This can be controlled via option export.comp.contrib.matrix in the method_control argument of fit_CWCurve() and fit_LMCurve().
1 parent 47f8b69 commit 961837c

9 files changed

+100
-33
lines changed

NEWS.Rmd

+13-1
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,24 @@ in `confint()` failed. This has now been fixed, and in cases of failures we
247247
report the error message received from `confint()` (#509, fixed in #510).
248248
* Argument `output.terminal` has been renamed to `verbose` for consistency
249249
with other functions.
250+
* The function has gained the new `method_control` argument, which can be used
251+
to control the saving of the component contribution matrix in the RLum.Results
252+
object it returns. This is now disabled by default: to restore the previous
253+
behaviour, add `method_control = list(export.comp.contrib.matrix = TRUE)` to
254+
the function call (fixed in #573).
250255

251256
### `fit_EmissionSpectra()`
252257
* The function can now return a data frame with the values of all curves
253258
plotted, so that it's much easier to produce alternative plots, by setting
254259
option `export.plot.data = TRUE` within the `method_control` argument (#569,
255-
fixed in #570).
260+
fixed in #570 and #573).
261+
262+
### `fit_LMCurve()`
263+
* The function has gained the new `method_control` argument, which can be used
264+
to control the saving of the component contribution matrix in the RLum.Results
265+
object it returns. This is now disabled by default: to restore the previous
266+
behaviour, add `method_control = list(export.comp.contrib.matrix = TRUE)` to
267+
the function call (fixed in #573).
256268

257269
### `get_RLum()`
258270
* If `get_RLum()` with `subset` was used on info objects of an `RLum.Analysis-class` object it

NEWS.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,28 @@
290290
fixed in \#510).
291291
- Argument `output.terminal` has been renamed to `verbose` for
292292
consistency with other functions.
293+
- The function has gained the new `method_control` argument, which can
294+
be used to control the saving of the component contribution matrix in
295+
the RLum.Results object it returns. This is now disabled by default:
296+
to restore the previous behaviour, add
297+
`method_control = list(export.comp.contrib.matrix = TRUE)` to the
298+
function call (fixed in \#573).
293299

294300
### `fit_EmissionSpectra()`
295301

296302
- The function can now return a data frame with the values of all curves
297303
plotted, so that it’s much easier to produce alternative plots, by
298304
setting option `export.plot.data = TRUE` within the `method_control`
299-
argument (#569, fixed in \#570).
305+
argument (#569, fixed in \#570 and \#573).
306+
307+
### `fit_LMCurve()`
308+
309+
- The function has gained the new `method_control` argument, which can
310+
be used to control the saving of the component contribution matrix in
311+
the RLum.Results object it returns. This is now disabled by default:
312+
to restore the previous behaviour, add
313+
`method_control = list(export.comp.contrib.matrix = TRUE)` to the
314+
function call (fixed in \#573).
300315

301316
### `get_RLum()`
302317

R/fit_CWCurve.R

+15-1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@
9292
#' @param plot [logical] (*with default*):
9393
#' enable/disable the plot output.
9494
#'
95+
#' @param method_control [list] (*optional*): options to control the output
96+
#' produced. Currently only the 'export.comp.contrib.matrix' (logical) option
97+
#' is supported, to enable/disable export of the component contribution
98+
#' matrix.
99+
#'
95100
#' @param ... further arguments and graphical parameters passed to [plot].
96101
#'
97102
#' @return
@@ -115,6 +120,7 @@
115120
#' `component.contribution.matrix`:
116121
#' [matrix] containing the values for the component to sum contribution plot
117122
#' (`$component.contribution.matrix`).
123+
#' Produced only if `method_control$export.comp.contrib.matrix = TRUE`).
118124
#'
119125
#' Matrix structure:\cr
120126
#' Column 1 and 2: time and `rev(time)` values \cr
@@ -135,7 +141,7 @@
135141
#' The function **does not** ensure that the fitting procedure has reached a
136142
#' global minimum rather than a local minimum!
137143
#'
138-
#' @section Function version: 0.5.3
144+
#' @section Function version: 0.5.4
139145
#'
140146
#' @author
141147
#' Sebastian Kreutzer, Institute of Geography, Heidelberg University (Germany)
@@ -182,6 +188,7 @@ fit_CWCurve<- function(
182188
verbose = TRUE,
183189
output.terminalAdvanced = TRUE,
184190
plot = TRUE,
191+
method_control = list(),
185192
...
186193
) {
187194
.set_function_name("fit_CWCurve")
@@ -212,6 +219,7 @@ fit_CWCurve<- function(
212219
.validate_logical_scalar(verbose)
213220
.validate_logical_scalar(output.terminalAdvanced)
214221
.validate_logical_scalar(plot)
222+
.validate_class(method_control, "list")
215223

216224
# Deal with extra arguments -----------------------------------------------
217225

@@ -230,6 +238,9 @@ fit_CWCurve<- function(
230238
ylab <- if("ylab" %in% names(extraArgs)) {extraArgs$ylab} else
231239
{paste("OSL [cts/",round(max(x)/length(x), digits = 2)," s]",sep="")}
232240

241+
method_control <- modifyList(x = list(export.comp.contrib.matrix = FALSE),
242+
val = method_control)
243+
233244
if ("output.path" %in% names(extraArgs))
234245
.throw_warning("Argument 'output.path' no longer supported, ignored")
235246

@@ -793,6 +804,9 @@ fit_CWCurve<- function(
793804
## Return Values
794805
##============================================================================##
795806

807+
if (!method_control$export.comp.contrib.matrix) {
808+
component.contribution.matrix <- NA
809+
}
796810
newRLumResults.fit_CWCurve <- set_RLum(
797811
class = "RLum.Results",
798812
data = list(

R/fit_LMCurve.R

+21-3
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,20 @@
144144
#' see Details). **Note:** requires input for `values.bg`.
145145
#'
146146
#' @param verbose [logical] (*with default*):
147-
#' terminal output with fitting results.
147+
#' enable/disable output to the terminal.
148148
#'
149149
#' @param plot [logical] (*with default*):
150-
#' returns a plot of the fitted curves.
150+
#' enable/disable the plot output.
151151
#'
152152
#' @param plot.BG [logical] (*with default*):
153153
#' returns a plot of the background values with the fit used for the
154154
#' background subtraction.
155155
#'
156+
#' @param method_control [list] (*optional*): options to control the output
157+
#' produced. Currently only the 'export.comp.contrib.matrix' (logical) option
158+
#' is supported, to enable/disable export of the component contribution
159+
#' matrix.
160+
#'
156161
#' @param ... Further arguments that may be passed to the plot output, e.g.
157162
#' `xlab`, `xlab`, `main`, `log`.
158163
#'
@@ -166,6 +171,7 @@
166171
#' `.. $fit` : nls ([nls] object)\cr
167172
#' `.. $component_matrix` : [matrix] with numerical xy-values of the single fitted components with the resolution of the input data
168173
#' `.. $component.contribution.matrix` : [list] component distribution matrix
174+
#' (produced only if `method_control$export.comp.contrib.matrix = TRUE`)
169175
#'
170176
#' **`info:`**
171177
#'
@@ -188,7 +194,7 @@
188194
#' global minimum rather than a local minimum! In any case of doubt, the use of
189195
#' manual start values is highly recommended.
190196
#'
191-
#' @section Function version: 0.3.4
197+
#' @section Function version: 0.3.5
192198
#'
193199
#' @author
194200
#' Sebastian Kreutzer, Institute of Geography, Heidelberg University (Germany)
@@ -259,6 +265,7 @@ fit_LMCurve<- function(
259265
verbose = TRUE,
260266
plot = TRUE,
261267
plot.BG = FALSE,
268+
method_control = list(),
262269
...
263270
) {
264271
.set_function_name("fit_LMCurve")
@@ -296,6 +303,10 @@ fit_LMCurve<- function(
296303
fit.method <- .validate_args(fit.method, c("port", "LM"))
297304
bg.subtraction <- .validate_args(bg.subtraction,
298305
c("polynomial", "linear", "channel"))
306+
.validate_logical_scalar(verbose)
307+
.validate_logical_scalar(plot)
308+
.validate_logical_scalar(plot.BG)
309+
.validate_class(method_control, "list")
299310

300311
## Set plot format parameters -----------------------------------------------
301312
extraArgs <- list(...) # read out additional arguments list
@@ -335,6 +346,9 @@ fit_LMCurve<- function(
335346

336347
fun <- if ("fun" %in% names(extraArgs)) extraArgs$fun else FALSE # nocov
337348

349+
method_control <- modifyList(x = list(export.comp.contrib.matrix = FALSE),
350+
val = method_control)
351+
338352
# layout safety settings
339353
par.default <- par()[c("mfrow", "cex", "mar", "omi", "oma")]
340354
on.exit(par(par.default), add = TRUE)
@@ -1025,6 +1039,10 @@ fit_LMCurve<- function(
10251039
##============================================================================#
10261040
## Return Values
10271041
##============================================================================#
1042+
1043+
if (!method_control$export.comp.contrib.matrix) {
1044+
component.contribution.matrix <- NA
1045+
}
10281046
newRLumResults.fit_LMCurve <- set_RLum(
10291047
class = "RLum.Results",
10301048
data = list(

man/fit_CWCurve.Rd

+8-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/fit_LMCurve.Rd

+10-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/_snaps/fit_LMCurve.md

+3-23
Large diffs are not rendered by default.

tests/testthat/test_fit_CWCurve.R

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ test_that("check functionality", {
4343
expect_equal(round(fit$data$I01, digits = 0), 2388, tolerance = 1)
4444
expect_equal(round(fit$data$lambda1, digits = 1), 4.6, tolerance = 1)
4545
expect_equal(round(fit$data$`pseudo-R^2`, digits = 0), 1)
46+
expect_type(fit@data$component.contribution.matrix, "list")
47+
expect_equal(fit@data$component.contribution.matrix[[1]], NA)
4648

4749
## RLum.Data.Curve object
4850
curve <- set_RLum("RLum.Data.Curve",
@@ -54,6 +56,7 @@ test_that("check functionality", {
5456
main = "CW Curve Fit",
5557
n.components.max = 4,
5658
log = "x",
59+
method_control = list(export.comp.contrib.matrix = TRUE),
5760
verbose = FALSE,
5861
plot = FALSE)
5962
expect_s4_class(fit, "RLum.Results")
@@ -62,6 +65,7 @@ test_that("check functionality", {
6265
expect_equal(round(fit$data$I01, digits = 0), 2388, tolerance = 1)
6366
expect_equal(round(fit$data$lambda1, digits = 1), 4.6, tolerance = 1)
6467
expect_equal(round(fit$data$`pseudo-R^2`, digits = 0), 1)
68+
expect_length(fit@data$component.contribution.matrix[[1]], 9000)
6569

6670
SW({
6771
expect_warning(fit_CWCurve(ExampleData.CW_OSL_Curve, fit.method = "LM",

tests/testthat/test_fit_LMCurve.R

+10
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ test_that("snapshot tests", {
4848
set.seed(1)
4949
fit <- fit_LMCurve(values.curve, values.bg = values.curveBG,
5050
n.components = 3, log = "x",
51+
method_control = list(
52+
export.comp.contrib.matrix = TRUE),
5153
start_values = data.frame(Im = c(170,25,400),
5254
xm = c(56,200,1500)))
5355
})
@@ -59,6 +61,8 @@ test_that("snapshot tests", {
5961
n.components = 3,
6062
log = "x",
6163
fit.method = "LM",
64+
method_control = list(
65+
export.comp.contrib.matrix = TRUE),
6266
plot = FALSE)
6367
})
6468
expect_snapshot_RLum(fit2, tolerance = snapshot.tolerance)
@@ -72,6 +76,8 @@ test_that("snapshot tests", {
7276

7377
set.seed(1)
7478
expect_snapshot_RLum(fit_LMCurve(values.curve, values.bg = values.curveBG,
79+
method_control = list(
80+
export.comp.contrib.matrix = TRUE),
7581
plot.BG = TRUE, bg.subtraction = "linear"),
7682
tolerance = snapshot.tolerance)
7783

@@ -94,10 +100,14 @@ test_that("snapshot tests", {
94100
skip_on_os("mac")
95101
expect_snapshot_RLum(fit_LMCurve(values.curve, values.bg = values.curveBG,
96102
xlim = c(0, 4000), ylim = c(0, 600), cex = 0.9,
103+
method_control = list(
104+
export.comp.contrib.matrix = TRUE),
97105
fit.calcError = TRUE),
98106
tolerance = snapshot.tolerance)
99107
expect_snapshot_RLum(fit_LMCurve(values.curve, values.bg = values.curveBG,
100108
plot.BG = TRUE, input.dataType = "pLM",
109+
method_control = list(
110+
export.comp.contrib.matrix = TRUE),
101111
bg.subtraction = "channel"),
102112
tolerance = snapshot.tolerance)
103113
skip_on_os("windows")

0 commit comments

Comments
 (0)