Programming Taskbook


E-mail:

Password:

User registration   Restore password

Russian

SFedU SMBU

Electronic problem book on programming

©  M. E. Abramyan (Southern Federal University, Shenzhen MSU-BIT University), 1998–2025

 

Examples | Python and R | PT4 types and functions

PrevNext


Additional functions

Support for the Python language was added in the Programming Taskbook version 4.11, and for the R language — in version 4.25.

Functions and the Node class described below will be available in a program if the pt4.py module for Python or the PT4.R module for R is imported in the program. Any template program created for task solving on Python and R imports the required module.

Functions for Python have names consisting of lowercase letters, in accordance with the traditional naming of functions in this language. Similar functions for the R language have names that begin with an uppercase letter to avoid conflict with the names of standard functions in that language. Function descriptions use Python names, but these descriptions also correspond to R functions of the same name, unless any differences are specifically noted.

Task initialization, data input-output


[Python]

task(name)

[R]

Task(name)

This function initializes a task named name (a string parameter). It must be called at the beginning of the program. If the source code does not contain the task function call then the program output the error message "The task function with a task name is not called".

A task name must contain a name of a task group and an order number (for example, "Begin3"). If the group name is invalid then the program output the error message "Invalid task group". If the task number is invalid then the program output the error message with information about the range of the available task numbers for this group. The symbol "?" placed after the task name (for example, "Begin3?") means that the program will be run in the demo mode.

The task function may be also used for creating and displaying an html-page containing a description of a task or a task group. In this case the name of the required task or the task group ended by the "#" symbol must be used for the name parameter, for example, "Begin3#" or "Begin#".

Starting from the version 4.13, the Programming Taskbook provides a program testing on several sets of input data during a single running of the program. You should place the sumbol "!" after the task name (for example, "Begin3!") in order to switch off this new feature.

All subsequent calls of the task function are ignored with the following exception: if several calls are used for creation of an html-page containing a description of various tasks or task groups then all these calls will be taken into account.

Starting from the version 4.12, the name parameter may include the "_en" or "_ru" suffix that determines the interface language (English or Russian respectively) for Programming Taskbook window and the task itself. The "?", "#", and "!" symbols should be placed before the suffix, for example, "Begin3#_en". If several calls of the task function are used (for creation of an html-page) then only the suffix of the first call will be taken into account. If the suffix is absent then the default language is applied (the default language may be changed by means of a pop-up menu of the PT4Load tool).


[Python]

get()
get_bool()
get_int()
get_float()
get_str()
get_Node()

[R]

Get()

These functions must be used to input initial data values in the program. They must be called after the task function, otherwise the program output the error message "The task function with a task name is not called at the beginning of the program".

Each function call returns the next item of input data. The get/Get function allows to input data item (vector of length 1 in case of R language) of any data type (bool/logical, int/integer, float/double, str/character or special type Node defined in the taskbook and described below). Initial data of character type are also input as strings (str/character). The other Python functions allow to input data item of definite type and must correspond to the type of data item, otherwise the program output the following message: "Invalid type is used for an input data item". For example, this message will be output if get_int function will be called for input a string.

In the case of input of more data than the task requires, the program output the error message "An attempt to input superfluous data". In the case of input of less data than the task requires, the program output the error message "Some required data are not input".


[Python]

get2()
get3()
get4()
get5()
get_list(n = -1)
get_matr(m = -1, n = -1)

[R]

GetV(len = 0)
GetM(nrow = 0, ncol = 0)

These functions for Python appeared in version 4.19. They make it easy to organize the input of multiple scalar data, as well as data sets to be stored in a list or in a matrix (list of lists).

The get2, get3, get4, get5 functions provide sequential calls to 2, 3, 4, and 5 get functions and return a tuple containing all the input data. For example, to enter three source data and assign them to variables a, b, c, it is sufficient to use the operator

[Python]

a, b, c = get3()

The function get_list without parameters firstly reads the size n of the input list (using the get_int function), then reads the n subsequent elements of the original data (using the get function) and adds them to the list, which is returned as the result of this function.

If a non-negative integer parameter n is explicitly specified when calling the get_list function, it is considered the size of the list; in this case, the function only reads list elements. Negative values of the parameter n mean that it is necessary to read the size of the list before reading the elements (thus, in the case of a negative parameter, the function behaves the same as when it is called without parameters). If the parameter is not an integer, an exception is thrown.

The function get_matr without parameters firstly reads the sizes m and n of the input matrix (using two get_int functions), then reads m*n subsequent elements of the original data (using the get function) and adds them to the list, which is returned as the result of this function. It is assumed that value m specifies the number of rows and corresponds to the first index of the resulting matrix, and value n specifies the number of columns and corresponds to the second index of the matrix. It is also assumed that matrix elements are read by rows. The resulting matrix is a list of lists. Thus, the operator a = get_matr() is equivalent to the following sequence of operators:

[Python]

m, n = get_int(), get_int()
a = [[get() for j in range(n)] for i in range(m)]

If two non-negative integer parameters m and n are explicitly specified when you call get_matr, they are treated as matrix dimensions; in this case, the function only reads matrix elements. If the second parameter (n) is not specified or is negative, and the first parameter (m) is specified and is non-negative, it is assumed that the matrix being input is a square matrix of order m; in this case, the function also inputs only matrix elements. Thus, to enter a square matrix (assuming that there is only one value before its elements, which is the matrix order), just execute the following operator:

[Python]

a = get_matr(get())

The GetV and GetM functions for the R language behave similarly to the get_list and get_matr functions of Python.

The GetV function without parameters reads an integer determining the size of the vector, and then reads the elements of the vector, after which it returns the obtained vector. This behavior corresponds to the default value of the len parameter, which is 0.

A version of this function with a single positive len parameter (GetV(len)) does not read the size of the vector, but immediately inputs values of its elements. If you specify a negative parameter or a parameter that has a fractional part or a parameter that is not a number, an error message is displayed. The type of vector elements is determined by the type of the first element read.

The GetM function without parameters reads two integers determining the matrix size (first the number of rows, then the number of columns), then reads the matrix elements, and returns the obtained matrix. This behavior corresponds to values of the parameters nrow and ncol equal to 0.

The version of this function with one positive parameter equal to m (GetM(m) or GetM(nrow = m) or GetM(ncol = m)) does not read the dimensions of the matrix, but immediately inputs its elements, assuming that the matrix is a square matrix of order m. The version of the function with two positive parameters nrow and ncol also does not read the dimensions of the matrix, but immediately inputs its elements, assuming that the matrix is a rectangular matrix of size nrow by ncol. If you specify negative parameters or parameters that have a fractional part or parameters that are not numbers, an error message is displayed. The type of matrix elements is determined by the type of the first element read. Input of elements is always performed by rows.


[Python]

put(a, ...)

[R]

Put(...)

The put function must be used to output results on the screen and compare obtained results with control data (i.e., correct results). It must be called after the task function, otherwise the program output the error message "The task function with a task name is not called at the beginning of the program".

For Python, the put function may be used for output one or more data items of any admissible type: bool, int, float, str, Node. Also it may output tuples and lists with items of above-mentioned types.

For the R language, any parameter may be an expression of logical, integer, double, character, Node type (in particular, vectors, matrices, arrays, factors, lists and data frames with elements of the specified types), as well as a constant NULL (empty object). Only the elements of data sets, without additional attributes, are passed to the taskbook for checking. When outputting a matrix or data frame, its elements are sent to the taskbook by rows. When outputting an array of a larger dimension (more than two), it is interpreted as a one-dimensional vector. If you try to output NA, NaN, Inf or -Inf values, an error message is output. The type of output data is checked; in particular, real numbers with a zero fractional part are not considered as integers.

Note that empty objects, as well as objects of the Node type, are required to be output only in tasks of the Dynamic and Tree groups and their analogs GCDyn and GCTree.

If one of parameters is of invalid type, then the program raises the ValueError exception with the error message "The put function has an argument of invalid type". A parameter type must correspond to the type of output data item, otherwise the program output the error message "Invalid type is used for an output data item".

In the case of output of more data than the task requires, the program output the error message "An attempt to output superfluous data". In the case of output of less data than the task requires, the program output the error message "Some data are not output".


[R]

GetCountries()
GetStudents()
PutN(dataframe)
GetF(filename, colnames, combine = 0)
PutF(dataframe, filename)

These specialized functions for the R language are intended for use in solving tasks from the TableBase and TableExt groups.

The GetCountries and GetStudents functions allow to input source tables (data frames) for TableBase group tasks (the GetCountries function returns the table with data on world countries and is used in TableBase1–10 tasks, the GetStudents function returns the table with data on students and is used in TableBase11–30 tasks).

The PutN(dataframe) function is executed similarly to the Put(nrow(dataframe), dataframe) function, i.e. it first outputs the number of rows of the dataframe, and then its elements; this function can be used in those tasks of the TableBase group, in which it is required to output not only the obtained table, but also its size (number of rows).

The GetF function is intended for input of initial file data in tasks of the TableExt group. It reads table data from a file named filename and associates the names specified in the colnames vector with the columns of the resulting table. In addition, it combines columns with combine and combine+1 numbers if the combine parameter is not equal to 0 (this action is required for columns with surnames and initials in TableExt49–TableExt70 tasks).

The PutF function saves data from the dataframe in a text file named filename. Each line of the file contains one row of the dataframe, where column values are separated by spaces and real numbers are displayed with two fractional signs.

In the program templates for all tasks of the TableBase and TableExt groups for the R language, the specified input functions are already called and their return values (tables) are stored in variables, for example:

[R]

d = GetF(Get(), c('Code', 'Year', 'Month', 'Len'))

By the parameter set of the GetF function, you can determine the table column names and their order.

In addition, the program templates for all TableExt group tasks for the R language contain comments that specify how to use the PutF function to output results, and similar comments for the PutN function are given in the templates for those TableBase group tasks in which this function can be used.

The Node class


[Python]

# Конструкторы:
   Node(data = 0, next = None, prev = None)
   Node.for_tree(data = 0, left = None, right = None, parent = None)
# Свойства (доступны для чтения и для записи):
   Data
   Next
   Prev
   Left
   Right
   Parent
# Метод, освобождающий ресурсы, используемые объектом Node:
   dispose()

[R]

# Конструкторы:
   Node(Data = 0L, Next = NULL, Prev = NULL)
   Node.ForTree(Data = 0L, Left = NULL, Right = NULL, Parent = NULL)
# Свойства (доступны для чтения и для записи):
   $Data
   $Next
   $Prev
   $Left
   $Right
   $Parent
# Функция, освобождающая ресурсы, используемые объектом Node:
   Dispose(node)

The Node class is used in the tasks of the Dynamic and Tree groups and their analogs GCDyn and GCTree. In the introductory tasks of the Dynamic group (Dynamic1–Dynamic2) and in the tasks devoted to stacks and queues (Dynamic3–Dynamic28) the Data and Next properties of the Node class are used. In the tasks devoted to lists (Dynamic29–Dynamic80) all properties (Data, Next, Prev) of Node class are used. In the most tasks devoted to binary trees the Data, Left, and Right properties of the Node class are used. The Parent property is used in the tasks devoted to doubly linked binary trees (Tree48–Tree56 and Tree70–Tree71).

Note that the dispose method should be called for any Node object, except objects that are output data for this task. If the dispose method is not called for required objects, then the program output the error message.

Output debug info

Functions described below are intended to output some debug data into the debug panel located below the task panels of the Programming Taskbook window.

Since version 4.22, the debug panel can contain text data with any Unicode characters.

Since the show functions for Python and R have a number of differences, separate descriptions are given for them.


[Python]

show(a, ...)

This function shows the debug data in the debug window located below the task window. The arguments of the show function may be of any type including tuples and lists; all data items are converted into their string representations (see below the description of the set_width and set_precision functions).

The string parameter may contain explicit line-breaks chr(10) or "\n" (new line).

In version 4.19, the implementation of the show function has been changed so as to provide formatted output of data structures, including nested ones. The following standard Python notation is used for output structures: tuples are surrounded by parentheses, lists by square brackets, sets and dictionaries are surrounded by curly brackets, keys and values of dictionary elements are separated by a colon. In addition, each element of a dictionary is enclosed in parentheses. Elements of structures are separated by commas (except for elements that are themselves sets, lists or dictionaries, after which no comma is specified, since such elements are separated by line breaks — see below).

When any structure with a variable number of elements (i.e., a set, list, or dictionary) is displayed, it is automatically moved to the next screen line in the debug section. If there are several nested structures, the level of nesting is indicated by additional indentation.

Below are examples of using the show function to output various data structures. The program fragment providing debugging output has the following form (the Matrix80 task was used, in which a real square matrix is given):

[Python]

     task("Matrix80")
     show_line("Matrix (list of lists) of real numbers (width = 5):")
     a = get_matr(get())
     set_width(5)
     show_line(a)
     show_line("Dictionary of string tuples (width = 0):")
     b1 = {1:("abc","d","efg"), 2:("123","456","7"), 22:("**","!!")}
     set_width(0)
     show_line(b1)
     show_line("Dictionary of string lists (width = 3):")
     b2 = {1:["abc","d","efg"], 2:["123","456","7"], 22:["**","!!"]}
     set_width(3)
     show_line(b2)
     show_line("List of lists containing numeric tuples (width = 2):")
     c1 = [[(1,2,3),(4,5,6)], [(7,8,9),(10,11,12)], [(13,14,15), (16,17,18)]]
     set_width(2)
     show_line(c1)
     show_line("List of lists containing numeric lists (width = 2):")
     с2 = [[[1,2,3],[4,5,6]], [[7,8,9],[10,11,12]], [[13,14,15], [16,17,18]]]
     show_line(с2)

In the following sample content of the debug section, note that when scalar or tuple elements are output, they are separated by commas, whereas after each list element, line breaking is performed. In addition, you should pay attention to the use of indents when outputting multidimensional lists, as well as to setting the width of output data using the set_width function.

  1>  Matrix (list of lists) of real numbers (width = 5):
  2>  [ [  0.14 ,  3.21 ,  7.86 ,  1.73 ,  9.20 ]
  3>    [  9.53 ,  6.22 ,  4.05 ,  9.19 ,  4.77 ]
  4>    [  0.24 ,  5.84 ,  3.35 ,  8.84 ,  1.32 ]
  5>    [  5.54 ,  1.75 ,  7.70 ,  7.30 ,  8.09 ]
  6>    [  0.97 ,  4.31 ,  0.90 ,  3.76 ,  6.06 ]
  7>  ]
  8>  Dictionary of string tuples (width = 0):
  9>  { ( 1 : ( abc , d , efg ) ) , ( 2 : ( 123 , 456 , 7 ) ) , ( 22 : ( ** , !! ) ) }
 10>  Dictionary of string lists (width = 3):
 11>  { (   1 : [ abc , d   , efg ]
 12>  ) (   2 : [ 123 , 456 , 7   ]
 13>  ) (  22 : [ **  , !!  ]
 14>  ) }
 15>  List of lists containing numeric tuples (width = 2):
 16>  [ [ (  1 ,  2 ,  3 ) , (  4 ,  5 ,  6 ) ]
 17>    [ (  7 ,  8 ,  9 ) , ( 10 , 11 , 12 ) ]
 18>    [ ( 13 , 14 , 15 ) , ( 16 , 17 , 18 ) ]
 19>  ]
 20>  List of lists containing numeric lists (width = 2):
 21>  [ [ [  1 ,  2 ,  3 ]
 22>      [  4 ,  5 ,  6 ]
 23>    ]
 24>    [ [  7 ,  8 ,  9 ]
 25>      [ 10 , 11 , 12 ]
 26>    ]
 27>    [ [ 13 , 14 , 15 ]
 28>      [ 16 , 17 , 18 ]
 29>    ]
 30>  ]

[R]

Show(...)

Allows any amount of any data to be output to the debug section. Vectors of length 1 are output without any additional framing characters; in particular, strings are not enclosed in quotes. Logical constants are output as TRUE and FALSE. Real numbers are output in fixed-point format with two fractional digits by default. If the output string contains "\n" characters, each such a character provides a line break in the debug section.

The zero-length vectors, matrices and multidimensional arrays are output as empty square brackets: [ ].

Vectors of length greater than 1 are enclosed in square brackets; spaces are printed between their elements.

Non-empty matrices are output as a set of line vectors enclosed in additional square brackets, with each line vector displayed on a separate screen line, and after the matrix is output, automatic line breaking is performed. The output of each matrix is automatically performed from the beginning of a new screen line. As an example, here is the output of the matrix created using the matrix(1:10, nrow= 4, ncol = 3) function:

[ [  1  5  9 ]
  [  2  6 10 ]
  [  3  7  1 ]
  [  4  8  2 ]
]

This example demonstrates the cyclic addition of matrix elements for the required size, as well as the fact that by default the created set of values is arranged by columns (recall that to fill the set by rows in the matrix function, it is enough to specify the byrow = TRUE parameter). Besides, from this example we can see that the matrix columns are automatically aligned. By default, the number of positions used to output each element is sufficient to output the "widest" element; in addition, an extra space is added between the elements.

Non-empty multidimensional arrays of dimension greater than two are output as a regular one-dimensional vector (obtained by transforming the original multidimensional array using the as.vector function). For them, the additional text “array” and information about the dimension (attribute dim) are specified inside square brackets, and the elements themselves are displayed on a new line. As an example, here is the output of a three-dimensional array created using the array(1:10, dim = c(2, 3, 4)) function:

[ array ( dim: [ 2 3 4 ] )
  1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 ]

As for matrices, before starting output of a multidimensional array and after its completion, automatic line breaking is performed.

If the dim attribute is present or absent, one-dimensional data sets are output in different ways (as usual vectors if dim is absent and as one-dimensional arrays if it is present). For example, when executing the fragment

[R]

a = array(1:10, dim = 10)
Show(a)
a = 1:10
Show(a)

the following text will be displayed in the debug section:

[ array ( dim: 10 )
  1 2 3 4 5 6 7 8 9 10 ]
[ 1 2 3 4 5 6 7 8 9 10 ]

Even more significant differences will appear in the case when a vector and a one-dimensional array consist of a single element:

[R]

  a = array(10, dim = 1)
  Show(a)
  a = 10
  Show(a)

The result will be as follows:

[ array ( dim: 1 ) 10.00 ]
10.00

The multidimensional array returned by the tapply function is automatically provided with the dimnames attribute, which plays an important role in further processing of this array. Therefore, if such an attribute is present, it is also displayed in the debug section on a separate line (between the line with information about the dim attribute and the line with the contents of the multidimensional array). Examples with the dimnames attribute are given below.

The Show function allows you to display not only vectors, matrices and arrays, but also other standard R language data structures. Below are samples of output of various structures.

Lists without additional attributes:

{ list $Int: 5 $Dbl: 3.14 $Char: "Example" $Vec: [ 4 5 6 7 ] }

Lists with additional attributes returned by the tapply function:

{ list ( dim: 7 )
dimnames[[ 1 ]]: [ "5" "6" "7" "8" "9" "10" "11" ]
$5: 10 $6: 7 $7: 7 $8: 5 $9: 7 $10: 12 $11: 5 }

Factors (unordered):

[ factor ( levels: Female Male ) Male Male Female Male Female Female ]

Ordered factors:

[ ordered factor ( levels: Low Medium High ) Medium Low High Medium ]

Tables (data frames):

{   $Name         $Gender $Height $Class $DevClub
  1 "Aleksandrov" Male        162      8     TRUE
  2 "Alekseeva"   Female      163      7    FALSE
  3 "Baranov"     Male        171      7     TRUE
  4 "Belkin"      Male        165      9     TRUE
  5 "Belousova"   Female      172     10    FALSE
  6 "Belyaeva"    Female      154      6    FALSE
}

In addition, a special format is provided for multidimensional arrays of any dimension (including matrices) containing an additional attribute dimnames. Such arrays can be returned by the tapply function. Here are examples of displaying arrays of dimension 1 and 2 with additional attributes:

[ array ( dim: 7 )
dimnames[[ 1 ]]: [ "5" "6" "7" "8" "9" "10" "11" ]
10 7 7 5 7 12 5 ]

[ array ( dim: [ 7 2 ] )
dimnames[[ 1 ]]: [ "5" "6" "7" "8" "9" "10" "11" ]
dimnames[[ 2 ]]: [ "Female" "Male" ]
5 5 1 2 2 6 3 5 2 6 3 5 6 2 ]

[Python]

show_line(a, ...)

[R]

ShowLine(...)

Modification of the previously described show function; after outputting all the specified data items to the debug section, this function additionally performs an automatic line break. It can be called without parameters, in which case it simply moves to the next line.

Since version 4.19, the Python show_line function only performs an additional line break if the last data item to be output is not a variable-length structure (e.g., a list, set, or dictionary), since for such structures, a line break is performed automatically after their output.

In the case of the R language, line breaking is performed only if such an action was not performed at the end of the output of the last data element (for example, in a matrix or a multidimensional array). Another feature of the ShowLine function for the R language is that its call without parameters provides a new line break only if the previous line containes some data (thus, multiple consecutive calls of several ShowLine functions without parameters will not lead to the appearance of empty lines in the debug section). If you want to add empty lines to the debug section, you can call the Show function with the string parameter "\n".


[Python]

show_s(a, ...)
show_line_s(a, ...)

[R]

ShowS(...)
ShowLineS(...)

Modifications of the previously described functions show and show_line, added in version 4.25. They are executed in the same way as the functions show and show_line, except that all strings specified in them are enclosed in double quotes and, in addition, the characters "\n" do not lead to a lline break, but are displayed in the line itself as a "\n" text. Using of these functions allows to display string data, which are not ordinary comments, more clearly in the debug section.


[Python]

set_width(w)

[R]

SetWidth(w)
SetWidthDF(...)

The set_width function is defined in the taskbook, starting from version 4.14. It specifies the minimum width w (0 <= w <= 100) of the output field for data elements output by functions of the show group (except for the special element "\n"); by default, the minimum width is set to 0. The function applies to all subsequent calls of the show function and all its modifications.

In the case of Python, numeric data is aligned on the right border (i.e., appended with spaces on the left), other data is aligned on the left border.

In the case of the R language, numeric and logical data are aligned on the right border, and string and factor data are aligned on the left border. Besides, in the case of R language, when outputting matrices, the number maxw of screen positions necessary for outputting the longest element is determined beforehand, and it is used as the width of the output field if the current width value previously set by SetWidth function is less than maxw.

The R language also has a SetWidthDF function that allows you to set the number of screen positions used to output table columns (data frames). By default, the number of screen positions for each column is 0, which means that the minimum required number of positions is used for output, and this number will be the same for all elements of the column (including its header). If the number of screen positions set by the SetWidthDF function is insufficient to output the column elements, the minimum required number of screen positions is used. As parameters of the SetWidthDF function, you can specify both individual numbers (without fractional part) and vectors of such numbers.


[Python]

set_precision(d)

[R]

SetPrecision(d)

The set_precision function is defined in the taskbook, starting from version 4.14. It allows to specify the format of real numbers representation. The parameter d must be in the range from -16 to 16. If d >= 0, numbers are displayed in the format with fixed point and d fractional digits. The default format is d = 2. When d < 0, numbers are displayed in exponential format with one digit in the integer part and -d digits in the fractional part. The function applies to all subsequent calls of the show function and its modifications.


[Python]

hide_task()

[R]

HideTask()

The hide_task function hides all sections of the Programming Taskbook window with the exception of the debug section (and therefore increases the debug panel height). If the debug panel contains no data, then the call of the hide_task function is ignored. All subsequent calls of this function are ignored too.

After displaying the Programming Taskbook window you can hide/restore task sections of this window by means of the space key or the command of the pop-up menu.

Additional features of the Programming Taskbook for the R language related to the %>% operation

If pdlyr package is used when solving tasks from Programming Taskbook in R language, and chains of function calls with %>% operations are used to transform tables (data frames), then you can include the Show, ShowLine, ShowS and ShowLineS functions in the transformation chain to output intermediate results of transformations in the debug section; in this case, they will output the obtained table and, if necessary, other data specified in the list of their parameters, for example:

[R]

res = tbl %>%
      select(...) %>% Show() %>%  # we output the table obtained as a result
                              # of executing the select(...) function
      filter(...) %>% Show(b, c) %>%  # we output the table obtained as a result
                              # of executing the select(...) function,
                              # as well as additional data b and c
      arrange(...)

The Show function and its modifications can be used in a chain of calls because they all return their first parameter unchanged.

If the task requires output the obtained table in the results section (or saving it in a file), the corresponding output function (Put, PutN and PutF) can be specified at the end of the call chain without saving the result of transformations in a special variable, for example:

[R]

tbl %>%
select(...)  %>% Show() %>%
filter(...)  %>% Show(b, c) %>%
arrange(...) %>% Show(b, c) %>%
PutF(filename)

You can also use special versions of functions for setting debug output parameters in the call chain:

SetW(data, w) is a version of the SetWidth(w) function,

SetWDF(data, ...) is a version of the SetWidthDF(...) function,

SetP(data, p) is a version of the SetPrecision(p) function.

The new versions add a "dummy" first parameter data, which is not used, but is returned by these functions. The presence of such a parameter allows you to include these function in chains, for example:

[R]

tbl %>%
SetW(20)   %>%   # set the width of the output field
SetP(4)    %>%   # set the number of fractional digits
select(...)  %>% Show() %>%
filter(...)  %>% Show(b, c) %>%
arrange(...) %>% Show(b, c) %>% PutF(filename)

Thus, these versions of setting functions behave similarly to C++ manipulators for output streams.


PrevNext

 

  Рейтинг@Mail.ru

Designed by
M. E. Abramyan and V. N. Braguilevsky

Last revised:
01.01.2025