XploRe provides a number of variables that customize the environment. Among others, a set of variables for modifying the output style in the output window is available:
Variable | Default |
outheadline | "\r\n Contents of %s\r\n\r\n" |
headline for arrays | |
outlayerline | "[,,%li,%li,%li,%li,%li,%li]\r\n" |
layerline for arrays | |
outlineno | "[%*li,]" |
line number style | |
outmaxdata | "2048" |
maximal output elements | |
outputformat | "% 8.5g" |
numeric output format string | |
outputstringformat | ""%s"" |
string output style |
The defaults can be checked by using getenv to print out the value of a variable. For example,
getenv("outmaxdata")prints the string
Contents of getenv [1,] "2048"which implies that not more than 2048 data items are printed.
The variable outmaxdata can now be modified by using setenv :
setenv("outmaxdata","100")changes the number of data items to 100. Of course, several of the above variables can be modified simultaneously.
Let us now consider the format strings which control the style of the headline, the line number and the array dimension. Consider a array of normal random numbers as an example:
randomize(0) x = normal(3,3,2) xThe default settings used in this extract from the output window:
outheadline | Contents of x |
outlayerline | [,,1,1,1,1,1,1] |
[1,] -0.21293 -1.3052 -0.38946 | |
outlineno | [2,] -1.0078 -1.4341 -1.5746 |
[3,] 1.9502 0.69812 -0.26595 | |
outlayerline | [,,2,1,1,1,1,1] |
[1,] 0.19947 -1.2245 0.20864 | |
outlineno | [2,] -2.5033 -0.42123 -0.14358 |
[3,] -0.49264 -0.72973 0.6273 |
The variable outheadline is used to influence the appearance of the
headline in the output window. The default value is
"\r\n
Contents of %s\r\n\r\n"
where %s is a placeholder for the name of the
variable. This results in the output of the words
Contents of x, assuming x is the variable to be printed,
followed by a blank line. Obviously, the combination of
\r\n
causes a line break.
It is possible to produce different outputs through the use of different format strings. No headline will be printed, when setenv ("outheadline", "") is used. Alternatively, an arbitrary headline, in this example a German title, can be produced.
randomize(0) x = normal(2,2,2) x setenv ("outheadline", "Inhalt von %s\r\n\r\n") x
Contents of x [,,1,1,1,1,1,1] [1,] -0.21293 1.9502 [2,] -1.0078 -1.3052 [,,2,1,1,1,1,1] [1,] -1.4341 -0.38946 [2,] 0.69812 -1.5746 Inhalt von x [,,1,1,1,1,1,1] [1,] -0.21293 1.9502 [2,] -1.0078 -1.3052 [,,2,1,1,1,1,1] [1,] -1.4341 -0.38946 [2,] 0.69812 -1.5746
Note that we use the special characters \r\n
to force
a new line in the output window. \n
is the new line
character used in C.
\r
is the special C character which forces the cursor
to jump to the first character in the current line.
Throughout this book, we have mostly used
setenv ("outheadline", "Contents of %s\r\n")to suppress the blank line after the headline.
With outlayerline it is possible to influence the appearance of the layer style in the output window. It should be noted that the layer line only appears in the output window if the array consists of more than one layer. In the following example, the layer line does not appear, since x is a matrix:
randomize(0) x = normal(2,2) xshows
Contents of x [1,] -0.21293 1.9502 [2,] -1.0078 -1.3052The default value for outlayerline is "[,,%li,%li,%li,%li,%li,%li]
\r\n"
where the %li are placeholders for the layer number.
XploRe
supports arrays up to eight dimensions.
The first two dimensions are regular rows and columns of a matrix.
These first two dimensions cannot be modified. Thus, we need
at most six placeholders of the form %li (which represents
a long integer, i.e. 64 bit on most machines)
for the remaining dimensions.
It is possible to produce different outputs through
the use of format strings. The following example shows
the default output and the output after setting the layerline
to the string "Layer: %s\r\n"
:
randomize(0) x = normal(2,2,2) x setenv ("outlayerline", "Layer: %li\r\n") x
Contents of x [,,1,1,1,1,1,1] [1,] -0.21293 1.9502 [2,] -1.0078 -1.3052 [,,2,1,1,1,1,1] [1,] -1.4341 -0.38946 [2,] 0.69812 -1.5746 Contents of x Layer: 1 [1,] -0.21293 1.9502 [2,] -1.0078 -1.3052 Layer: 2 [1,] -1.4341 -0.38946 [2,] 0.69812 -1.5746
Note that in this last example we use only one placeholder %li instead of the potential six. Since this example contains only one additional layer beyond the regular rows and columns of a matrix -- normal(2,2,2) means 2 rows, 2 columns and 2 layers -- one placeholder is sufficient.
With outlineno it is possible to influence the appearance of the line numbers of an array in the output window. The default value for this parameter is "[%*li,]", where %*li is a placeholder for the line number.
The following example shows the default output and the output after setting the layerline to the string "Line: %*li:
randomize(0) x = normal(10,2) x setenv ("outlineno", "Line %*li: ") x
Contents of x [ 1,] -0.21293 -2.5033 [ 2,] -1.0078 -0.49264 [ 3,] 1.9502 -1.2245 [ 4,] -1.3052 -0.42123 [ 5,] -1.4341 -0.72973 [ 6,] 0.69812 0.20864 [ 7,] -0.38946 -0.14358 [ 8,] -1.5746 0.6273 [ 9,] -0.26595 0.059032 [10,] 0.19947 0.44835 Contents of x Line 1: -0.21293 -2.5033 Line 2: -1.0078 -0.49264 Line 3: 1.9502 -1.2245 Line 4: -1.3052 -0.42123 Line 5: -1.4341 -0.72973 Line 6: 0.69812 0.20864 Line 7: -0.38946 -0.14358 Line 8: -1.5746 0.6273 Line 9: -0.26595 0.059032 Line 10: 0.19947 0.44835
For matrices with more than 9 rows, a right-justified line number should be used. This is accomplished by including a * into the placeholder: The default setting [%*li,] uses this.
This subsection considers the variables outputformat, outputstringformat and outmaxdata, which influence the format and the length of objects, that can be printed to the output window. All code examples for this section can be found in the quantlet XLGiofmt07.xpl .
outputformat sets the default output format for numeric arrays to % 8.5g. This format string means that the g-format is used with 5 decimals a total string length of 8. The variable outputformat can be changed now by using setenv :
setenv("outputformat","% 8.6g")changes the number of decimals to 6. For outputformat one can use the same string format as for the function string . See Section 15.3 for examples on formatting numeric output.
The variable outputstringformat sets the default format for text arrays. The default is ""%s"". For example,
x="a"~"bb" xgives
Contents of x [1,] "a" "bb"in the output window. It is sometimes convenient to suppress the quotation marks. Using
setenv("outputstringformat","%s") xwe obtain
Contents of x [1,] a bb
Finally, the variable outmaxdata can change the number of maximal data items in the output window. The default is 2048. Note that the number of data items is also restricted by a size restriction of 32 Kilobytes for each output item.
By default, all output is printed in the output window. The function output can save output additionally to a file. The function output must be called with one of the following options:
x=uniform(2,2) x ; usual output output("output.txt","reset") x+2 ; output goes also to output.txt output("output.txt","close") x+4 ; usual output output("output.txt","append") x+8 ; output goes also to output.txt output("output.txt","close")