File: AAAparameter.R

package info (click to toggle)
r-cran-tsp 1.1-6-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,128 kB
  • sloc: ansic: 277; sh: 13; makefile: 2
file content (64 lines) | stat: -rw-r--r-- 2,085 bytes parent folder | download
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
#######################################################################
# Code to check parameter/control objects
# Copyrigth (C) 2011-2016 Michael Hahsler
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


## helper to parse parameter lists with defaults
.nodots <- function(...) {
  l <- list(...)
  if(length(l) > 0L) warning("Unknown arguments: ",
    paste(names(l), "=",l, collapse=", "))
}

.get_parameters <- function(parameter, defaults) {
  defaults <- as.list(defaults)
  parameter <- as.list(parameter)

  ## add verbose
  if(is.null(defaults$verbose)) defaults$verbose <- FALSE

  if(length(parameter) != 0) {
    o <- pmatch(names(parameter), names(defaults))

    ## unknown parameter
    # if(any(is.na(o))){
    #   warning(sprintf(ngettext(length(is.na(o)),
    #     "Unknown parameter: %s",
    #     "Unknown parameters: %s"),
    #     paste(names(parameter)[is.na(o)],
    #       collapse = ", ")), call. = FALSE, immediate. = TRUE)
    #
    #   cat("Available parameter (with default values):\n")
    #   #print(defaults)
    #   cat(rbind(names(defaults)," = ", gsub("\n"," ",as.character(defaults))),
    #     sep=c("\t"," ","\n"))
    # }

    defaults[o[!is.na(o)]] <- parameter[!is.na(o)]
  }

  if(defaults$verbose) {
    cat("Used parameters:\n")
    #print(defaults)
    cat(rbind(names(defaults)," = ",
      strtrim(gsub("\n"," ",as.character(defaults)), 50)),
      sep=c("\t"," ","\n"))
  }

  defaults
}