MyNixOS website logo
Description

Adaptive Builder for Formatted Strings.

Provides a set of functions to facilitate building formatted strings under various replacement rules: C-style formatting, variable-based formatting, and number-based formatting. C-style formatting is basically identical to built-in function 'sprintf'. Variable-based formatting allows users to put variable names in a formatted string which will be replaced by variable values. Number-based formatting allows users to use index numbers to represent the corresponding argument value to appear in the string.

rprintf

Linux Build Status Windows Build status Coverage Status CRAN Version

rprintf is an adaptive builder for formatted strings. Currently it provides a set of tools for building formatted strings under various replacement rules:

  • C-style formatting with sprintf
  • Number-based formatting
  • Variable-based formatting

The primary goal of this package is to make it easier to produce formatted strings in all popular styles.

Installation

You can install from CRAN with

install.packages("rprintf")

or you can install the latest development version from GitHub with

devtools::install_github("rprintf","renkun-ken")

Examples

The following examples demonstrate how rprintf functions works. You should be familiar with how sprintf works first. See the documentation for more details.

C-style formatting

library(rprintf)
rprintf("Hello, %s", "world")
[1] "Hello, world"
rprintf("%s (%d years old)", "Ken", 24)
[1] "Ken (24 years old)"
rprintf("He is %d but has a height of %.1fcm", 18, 190)
[1] "He is 18 but has a height of 190.0cm"

Number-based formatting

rprintf("Hello, {1}", "world")
[1] "Hello, world"
rprintf("{1} ({2} years old)","Ken",24)
[1] "Ken (24 years old)"
rprintf("He is {1} but has a height of {2:.2f}cm",18,190)
[1] "He is 18 but has a height of 190.00cm"
rprintf("{1}, {2:.1f}, {3:+.2f}, {2}, {1:.0f}",1.56,2.34,3.78)
[1] "1.56, 2.3, +3.78, 2.34, 2"
rprintf("{2},{1}","x","y")
[1] "y,x"

Variable-based formatting

rprintf("Hello, $name", name="world")
[1] "Hello, world"
rprintf("$name ($age years old)",name="Ken",age=24)
[1] "Ken (24 years old)"
rprintf("He is $age but has a height of $height:.2fcm",age=18,height=190)
[1] "He is 18 but has a height of 190.00cm"
rprintf("$a, $b:.1f, $c:+.2f, $b, $a:.0f",a=1.56,b=2.34,c=3.78)
[1] "1.56, 2.3, +3.78, 2.34, 2"

For each type of formatting, a specialized function is also provided. rprintv only handles named variable-based formatting, and rprintn only handles number-based formatting.

License

This package is under MIT License.

Metadata

Version

0.2.1

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows