Last data update: 2014.03.03

R: Convert a value to a string.
paramValueToStringR Documentation

Convert a value to a string.

Description

Useful helper for logging. For discrete parameter values always the name of the discrete value is used.

Usage

paramValueToString(par, x, show.missing.values = FALSE,
  num.format = "%.3g")

Arguments

par

[Param | ParamSet]
Parameter or parameter set.

x

[any]
Value for parameter or value for parameter set. In the latter case it must be named list. For discrete parameters their values must be used, not their names.

show.missing.values

[logical(1)]
Display “NA” for parameters, which have no setting, because their requirements are not satified (dependent parameters), instead of displaying nothing? Default is FALSE.

num.format

[character(1)]
Number format for output of numeric parameters. See the details section of the manual for sprintf for details.

Value

[character(1)].

Examples

p = makeNumericParam("x")
paramValueToString(p, 1)
paramValueToString(p, 1.2345)
paramValueToString(p, 0.000039)
paramValueToString(p, 8.13402, num.format = "%.2f")

p = makeIntegerVectorParam("x", len=2)
paramValueToString(p, c(1L, 2L))

p = makeLogicalParam("x")
paramValueToString(p, TRUE)

p = makeDiscreteParam("x", values=list(a=NULL, b=2))
paramValueToString(p, NULL)

ps = makeParamSet(
  makeNumericVectorParam("x", len=2L),
  makeDiscreteParam("y", values=list(a=NULL, b=2))
)
paramValueToString(ps, list(x=c(1,2), y=NULL))

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(ParamHelpers)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/ParamHelpers/paramValueToString.Rd_%03d_medium.png", width=480, height=480)
> ### Name: paramValueToString
> ### Title: Convert a value to a string.
> ### Aliases: paramValueToString
> 
> ### ** Examples
> 
> p = makeNumericParam("x")
> paramValueToString(p, 1)
[1] "1"
> paramValueToString(p, 1.2345)
[1] "1.23"
> paramValueToString(p, 0.000039)
[1] "3.9e-05"
> paramValueToString(p, 8.13402, num.format = "%.2f")
[1] "8.13"
> 
> p = makeIntegerVectorParam("x", len=2)
> paramValueToString(p, c(1L, 2L))
[1] "1,2"
> 
> p = makeLogicalParam("x")
> paramValueToString(p, TRUE)
[1] "TRUE"
> 
> p = makeDiscreteParam("x", values=list(a=NULL, b=2))
> paramValueToString(p, NULL)
[1] "a"
> 
> ps = makeParamSet(
+   makeNumericVectorParam("x", len=2L),
+   makeDiscreteParam("y", values=list(a=NULL, b=2))
+ )
> paramValueToString(ps, list(x=c(1,2), y=NULL))
[1] "x=1,2; y=a"
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>