var.info: Get a detailed list of variables

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/var.info.R

Description

This function provides a detailed information of variables in the specified environment. If no environment and list of variables provided for the function, it will consider all existing variables in global environment.

Usage

1
2
3
    var.info(list="ALL", regex = NULL, envir=.GlobalEnv, human.readable=TRUE,
             sortby="size", decreasing=TRUE, n=Inf, beautify = FALSE,
             progressbar = FALSE)

Arguments

list

A list of variables which you want to get information for. If not specified, it gets all variables (Optional)

regex

A regular expression to be applied on the list of variables. This is very useful for example when 'list = "ALL"'. (Optional)

envir

The environment in which you want this function to be functional. (Optional)

human.readable

If you want to have the variable size in humar readable format (Kb, Mb, etc.). (Optional)

sortby

The name of a column that you wish to sort the output with. If not specified the result will be sorted by "size". Valid options are "name", "class", "size" or "detail". (Optional)

decreasing

A logical parameter (TRUE/FALSE) indicating that you want the sort to be done decreasingly or increasingly. If not specified it is TRUE. (Optional)

n

Number of desired rows in output If you want to have top 10, n should be equal to 10. If not specified the output will include all variables. (Optional)

beautify

A Logical parameter indicating whether the output should beautified. At the moment it just adds a up/down triangle in the column name, showing the sort direction and based which column the table is sorted. Default value is FALSE. See Details for more information. (optional)

progressbar

A Logical parameter indicating whether user wants to see progressbar or not. Default value is FALSE. See Details for more information. (optional)

Details

This function is a quick way to have some basic information about a list of variables. By modifying and changing the default parameters, you can narrow down the variables you are investigating. The main objective of this fuction is providing the following information about the variables in an easy and intuitive way: class size (amount of memory the variable has occupied) detail (dimention for data.frame and matrices and length of vectors)

In case the variable is a matrix or data.frame, in detail column the dimention will be provided, if it is a vector, the length will be reported, otherwise you will see NA in detail column for that specific variable.

This function is usually very quick but in case of having many variables in the environment, it might take some time, hence a progressbar is implemented to inform user about the process.

Value

The output will be a sorted data.frame with 4 columns. The "name" column contains the name of each variable, column "class" contains the class of each variable, columns "size" show the amount of memory the variable is occupying (it can be configured to be in bytes or human readable format. for this use the human.readable parameter.) and "detail" column includes variable-specific information (for matrices and data.frames the dimention and for vectors their list will be reported.)

Author(s)

Mehrad Mahmoudian

See Also

class, object.size

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
    ###### generate some variables ######
    # a data.frame
    data(iris)
    
    # some character vector
    for(i in 1:5){
        assign(letters[i], paste("some random text:",
                                 paste0(letters[runif(5, 1, 26)],
                                 collapse="")))
    }
    
    # a list
    f <- lapply(5:10, function(x){paste("some random text:",
                                  paste0(letters[runif(5, 1, 26)],
                                  collapse=""))})


    ###### demo of this function ######
    # basic usage
    var.info()
    
    # the sorting
    var.info(sortby="name", decreasing=FALSE)
    
    # select using regular expression
    var.info(regex="^i")
    
    # having the top 5 objects that use most memory in a beautified output
    var.info(n=5, sortby="size", decreasing=TRUE, beautify=TRUE)

varhandle documentation built on Feb. 21, 2020, 1:07 a.m.