Next: printoptions() Up: MacAnova Help File Previous: primefactors()   Contents

print()

Usage:
print(a, b, ...[,format:Fmt or nsig:m, header:F, labels:F, notes:T,\
  width:w, height:h, macroname:T, missing:missStr, name:setName]\
  [, file:fileName [,new:T]]]), Fmt, missStr, fileName, setName
  CHARACTER scalars, m > 0, w >= 30, h >= 12 integers



Keywords: output, missing values
                                  Usage
print(a,b, ...) prints objects (variables, expressions, macros) a, b,
....  By default the names 'a', 'b', ... are printed.

By default, print() formats REAL items using the format identified by
'format' on getoptions() output.  This normally is floating point with 5
significant digits.  Type help(options:"format") for details.

  Cmd> print(PI,sqrt(2)*run(5))
  PI:
  (1)      3.1416
  VECTOR:
  (1)      1.4142      2.8284      4.2426      5.6569      7.0711

print() encloses macros and the elements of CHARACTER variables in
quotes ("").  Any internal quotes are escaped with '\' (for example
"\"Hello\"") and non-printable characters are printed as escaped octal
integers (for example, "\033" or "\177").

  Cmd> a <- vector("Charlie","Dog"); print(a)
  a:
  (1) "Charlie"
  (2) "Dog"

print(Message), where Message is a single quoted string or CHARACTER
scalar, prints Message just as it is, without enclosing quotes and
without any internal quotes and non-printable characters escaped.

  Cmd> print("Charlie is a good dog!")
  Charlie is a good dog!

print(Message, macroname:T) does the same, except that when executed in
a macro, " in macro XXXX" is appended to Message.  This is useful for
printing messages in a macro.

You can modify the behavior of print using keywords 'format', 'nsig',
'missing', 'zero', 'labels', 'header', and 'notes'.  See below.

When either of keywords 'format' or 'nsig' are used, print() is
identical to write() with the same arguments.

print() is particularly useful in macros and inside {...}.

                           Printing to a file
print(a,b,...,file:FileName [,new:T]) where FileName is a quoted string
or CHARACTER variable, writes the output to the specified file rather
than to the screen.  With 'new:T', any information in the file is
discarded before writing.  Without 'new:T', output is appended to the
end of the file.

When FileName is the variable CONSOLE or a CHARACTER variable whose
value is "CONSOLE", the output is written to the screen or output window
rather than to a file.

                             Use of keywords
Keywords 'nsig', 'format', 'name', 'header', 'labels', 'notes',
'missing' and 'zero' are all recognized and can appear more than once.
They affect the printing of objects that follow them, until they are
changed except that a value for 'name' is used only once.  Any of them
that follow all items to be printed are treated as coming before all
items.  For example,
  Cmd> print(x,nsig:5,y,nsig:10)
and
  Cmd> print(nsig:10,x, nsig:5,y)
are equivalent.

Keywords 'file' and 'new' can appear only once, anywhere in the argument
list.

                      Keywords 'nsig' and 'format'
print(nsig:d,a,b,...) or print(a,b,...,nsig:d) prints numbers with d
significant digits in floating point format with width d+7.

  Cmd> print(PI,nsig:7)
  PI:
  (1)       3.141593

print(format:Fmt,a,b,...) or print(a,b,...,format:Fmt), where Fmt is a
quoted string or CHARACTER variable, prints numbers according to
specifications given in Fmt.

Fmt must be of the form "w.df" or "fw.d" (fixed point) or "w.dg" "gw.d"
(floating point) where w (field width) and d (decimals or significant
digits) are integers, for example "6.3f" or "g15.7".  See below for
details.

  Cmd> print(1000*PI,format:"12.6f") # fixed with 6 decimals
  NUMBER:
  (1)  3141.592654

                          Name header keywords
print(name:Name, a, b,... ) prints a with the name specified by
quoted string or CHARACTER scalar Name on the header.

Name can be of unlimited length aiding the creation of informative
output.

  Cmd> print(3*log(640320)/sqrt(163), nsig:17,\
     name:"3*log(640320)/sqrt(163) is a good approximation to pi")
  3*log(640320)/sqrt(163) is a good approximation to pi:
  (1)       3.1415926535897931

The value of 'name' is used for only one output variable; however, you
can have several instances of name:Name, each affecting the next
variable output.

Alternatively, if the name is a legal MacAnova variable name no more
than 10 characters long you can use a keyword to specify the name.  For
example print(name:"Residuals", r) and print(Residuals:r) are
equivalent.

print(header:F,x,header:T,y,...,) prints x without and y with an
identifying name.

  Cmd> print(PI,header:F)
  (1)      3.1416

                      Keywords 'width' and 'height'
print(a,b,...,width:w) temporarily sets option 'width' to w, an integer
>= 30. This affects how many items are printed per line.

print(a,b,...,height:h) temporarily set option 'height' to h, an integer
>= 12.  This affects the number of lines in any graphs being printed as
"dumb" plots and how often output will be paused in non-windowed
versions.

                            Keyword 'labels'
By default, print() prints coordinate labels, if they exist, or the
index or indices of the first element in each line otherwise.  See topic
'labels'.  Use of 'labels:F' suppresses printing of labels or indices.
A later 'labels:T' re-enables such printing.

  Cmd> print(PI,labels:F) # leading index (1) suppressed
  PI:
        3.1416

                             Keyword 'notes'
Keyword phrase 'notes:T' directs that any notes attached to variables
are printed above the values.

  Cmd> Pi <- vector(PI,labels:"pi",notes:"Copy of variable PI")

  Cmd> print(Pi,notes:T)
  Pi:
  Copy of variable PI
            pi
                  3.1416

See topic 'notes' for details on attached notes.

                            Keyword 'missing'
print(missing:MissStr1,a,b,...), where MissStr is a quoted string or
CHARACTER variable such as "?" or "NA", specifies that all missing
values are to be printed using MissStr.  If 'missing' is not used,
missing values are printed as "MISSING" (or using a different default if
you changed it by setoptions(); type help(options:"missing")).  Note
that this differs from the use of 'missing' on matprint() and matwrite()
for which the value must be a REAL scalar.

  Cmd> print(vector(PI,?,run(3)),missing:"NA")
  VECTOR:
  (1)      3.1416          NA           1           2           3

print(x,file:FileName,new:T,header:F,labels:F,missing:"?") writes x to
the file in a form that can be read by vecread().

                             Keyword 'zero'
print(zero:ZeroStr,a,b,...), where ZeroStr is a quoted string or
CHARACTER variable such as " ", "0" or "ZERO" specifies that zero values
are to be printed using ZeroStr.  If 'zero' is not used, zero values are
printed using the same format as other numbers.

  Cmd> print(PI*run(-2,2),zero:"Zero")
  VECTOR:
  (1)     -6.2832     -3.1416        Zero      3.1416      6.2832

                   Details on value of 'format' keyword
If Fmt is "w.df" or "fw.d" (fixed point), or "w.dg" or "gw.d" (floating
point), integer w specifies a field width of at least w characters.  For
fixed point format, integer d is the number of digits that will follow
the decimal point.  For floating point format, d is the number of
significant digits printed.  If w is omitted (".3f" / "f.3" or ".7g" /
"g.7"), it is implicitly set to d+7 ("10.3f"/ "f10.3" or "14.7g" /
"g14.7").  If w > 27, width = 27 is assumed and if d > 20, digits = 20
is assumed.

With fixed point output, trailing zeros are kept; for floating point
output they are trimmed off.  For example, 10.30 is printed as
'10.30000' with "8.5f" or "f8.5" format and as '10.3' with "8.5g" or
"g8.5" format.

For floating point output, exponential form, 9.3e+07 for example, is
used if required to represent the number.

You can change the default format for print() and matprint() by
setoptions() using keywords 'nsig' or 'format'.  See topics
'setoptions', 'options'.

                                Examples
Examples:
  print(nsig:5,a), print(format:"12.5g",a), and print(a,nsig:5),
are equivalent.
  print(nsig:5,file:"myfile",a,new:T)
writes a to file "myfile", starting fresh.

  Cmd> print("Quoted because > 1 argument",vector("a","Escaped\1\2"))
  STRING:
  (1) "Quoted because > 1 argument"
  VECTOR:
  (1) "a"
  (2) "Escaped\001\002"

  Cmd> print("Not quoted because only 1 argument")
  Not quoted because only 1 argument

Keywords that are not otherwised recognized are used to label output.
Keywords may have no more than 10 characters.

  Cmd> print(run(5)) # no labeling keyword
  VECTOR:
  (1)           1           2           3           4           5

  Cmd> print(one2five:run(5)) 3 with labelling keyword
  one2five:
  (1)           1           2           3           4           5

                            Cross references
See also topics 'options', write(), matprint(), matwrite(), paste(),
error().


Gary Oehlert 2005-08-12