bc: R to bc interface

Description Usage Arguments Details Value Note References Examples

Description

Interface to bc calculator.

Usage

1
2
3
bc(..., scale = getOption("bc.scale"), 
	retclass = c("bc", "character", "logical", "numeric"),
	cmd, args = "-l", verbose = getOption("bc.verbose"))

Arguments

...

Each argument is a line passed to bc.

scale

Number of decimals. If unspecified, the value is taken from the bc.scale option and if that is also unspecified, min(100, BC_LINE_LENGTH/2) is used if the BC_LINE_LENGTH environment variable was specified and 100 if a value for that environment variable was not specified.

retclass

class of returned value.

cmd

Character string representing the bc command. Default is to use "bc" but if that is not found on path it looks in bcdir in the bc package directory. On Windows the bcInstall() command can be used to automatically download and install bc in bcdir. On UNIX systems bc is normally present on path so no action need be taken.

args

Arguments used when issuing bc command.

verbose

Displays input and output to bc. For debugging. Logical or can use NULL to represent FALSE.

Details

Passes its arguments to bc and collects the result back as a "bc" class object. There are "bc" methods for print, S3 Ops and exp, log, atan, sin and cos.

The default action is to collapse all lines that are returned into a single line but if the user sets the BC_LINE_LENGTH environment variable, e.g. Sys.setenv(BC_LINE_LINE=100), say, then no collapsing will be done and its the responsibility of the user to ensure that the number specified is sufficiently large.

Note that in bc the % operator does not mean integer remainder when scale is nonzero.

bc variable and function definitions are not maintained from one call of bc to the next.

Value

Returns an object of class c("bc", "character").

Note

The bc function runs the bc executable. This is normally included with UNIX so no further setup is needed on that platform. For Windows, bc can be downloaded by issuing the R command bcInstall() with no arguments. This will download it into the package itself and subsequent calls to bc will find it. Alternately Windows users can download bc from the Download area of the home page of this package on googlecode placing it anywhere in their path.

References

Main Gnu bc site: http://www.gnu.org/software/bc/, Windows distribution: http://sourceforge.net/projects/unxutils, Another Windows distribution (less convenient since it requires readline4.dll): http://gnuwin32.sourceforge.net/packages/bc.htm.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## Not run: 
# all these are the same
bc("1.1^100")
bc(1.1) ^ 100
zero <- bc(0); (zero + 1.1) ^ 100

# both these are same
bc("x=1; 1+x+x^2/2+x^3/6+x^4/24 - e(x)")
x <- bc(1); 1+x+x^2/2+x^3/6+x^4/24 - exp(x)

# both these are same
bc("define sqr(x) {\nreturn(x*x)}; sqr(10)")
sqr <- function(x) x*x; x <- bc(10); sqr(x)

## End(Not run)

ggrothendieck/r-bc documentation built on May 17, 2019, 4:17 a.m.