printf: C-style formatted output

Description Usage Arguments Value Author(s) See Also Examples

Description

C-style formatted output.

Usage

1
2
## Default S3 method:
printf(fmt, ..., sep="", file="")

Arguments

fmt

A character vector of format strings. See same argument for sprintf().

...

Additional arguments sprintf().

sep

A character vector of strings to append after each element.

file

A connection, or a character of a file to print to. See same argument for cat().

Value

Returns nothing.

Author(s)

Henrik Bengtsson

See Also

For C-style formatting of character strings, see sprintf().

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
  cat("Hello world\n")
  printf("Hello world\n")

  x <- 1.23
  cat(sprintf("x=%.2f\n", x))
  printf("x=%.2f\n", x)

  y <- 4.56
  cat(sprintf(c("x=%.2f\n", "y=%.2f\n"), c(x,y)), sep="")
  printf(c("x=%.2f\n", "y=%.2f\n"), c(x,y))

Example output

Loading required package: R.oo
Loading required package: R.methodsS3
R.methodsS3 v1.7.1 (2016-02-15) successfully loaded. See ?R.methodsS3 for help.
R.oo v1.21.0 (2016-10-30) successfully loaded. See ?R.oo for help.

Attaching package: 'R.oo'

The following objects are masked from 'package:methods':

    getClasses, getMethods

The following objects are masked from 'package:base':

    attach, detach, gc, load, save

R.utils v2.5.0 (2016-11-07) successfully loaded. See ?R.utils for help.

Attaching package: 'R.utils'

The following object is masked from 'package:utils':

    timestamp

The following objects are masked from 'package:base':

    cat, commandArgs, getOption, inherits, isOpen, parse, warnings

Hello world
Hello world
x=1.23
x=1.23
x=1.23
y=4.56
x=1.23
y=4.56

R.utils documentation built on Sept. 26, 2021, 9:07 a.m.