track.info: Return filenames and directories for tracked variables.

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

View source: R/track.info.R

Description

Return filenames and directories for tracked variables.

Usage

1
2
3
4
5
6
7
track.filename(expr, list = character(0), pos = 1,
               envir = as.environment(pos), suffix = FALSE)
track.datadir(pos = 1, envir = as.environment(pos), relative = TRUE)
track.info(pos = NULL, envir = as.environment(pos), all=is.null(pos))
track.mem(pos = NULL, envir = as.environment(pos), all=is.null(pos))
env.is.tracked(pos = 1, envir = as.environment(pos))
tracked.envs(envirs=search())

Arguments

expr

An unquoted variable name

list

A character vector of variable names

pos

The search path position of the environment being tracked (default is 1 for the global environment)

envir

The environment being tracked. This is an alternate way (to the use of pos=) of specifying the environment being tracked, but should be rarely needed.

suffix

: Return the filename with the RData suffix (extension) (taken from track.options("RDataSuffix"))

relative

: Return a path relative to the current working directory, or an absolute path?

all

Return info about all tracked environments?

envirs

A list or vector of objects that can be interpreted as environments by as.environment

Value

track.filename()

returns the filenames for tracked variables. These names are guaranteed to be distinct for distinct variables.

track.datadir()

returns the directory in which RData files for tracked variables are stored.

track.info:

returns a dataframe of information (directory, readonly/writable status) about environments currently tracked.

track.mem:

returns a dataframe of information (number of objects, memory usage) about environments currently tracked.

env.is.tracked:

returns TRUE or FALSE

tracked.envs:

with no arguments, it returns the names of tracked environment that are on the search list. If given an argument that is a vector of environments (or environment names), it returns the subset of that vector that are tracked environments.

Note

The track package stores RData files in the directory returned by track.datadir(). It is not advisable to write other RData files to that directory. Filenames for variables may change when an object is deleted and then recreated.

A warning message like "env R_GlobalEnv (pos 1 on search list) appears to be an inactive tracked environment, saved from another session and loaded here inappropriately" indicates that the environment has some but not all of the structure of a tracked environment. In particular, the variable .trackingEnv exists in it, but does not seem to be connected properly. Some of the bindings may be active bindings, but they may have come disconnected from the tracking environment. The most common way that this kind of situation can arise is from doing save.image() before track.stop(), and then reloading the saved image (e.g., when restarting R). To fix this situation, do the following:

  1. rm(.trackingEnv, pos=1)

  2. names(which(!sapply(ls(pos=1), bindingIsActive, as.environment(1)))) # to see which variables have active bindings

  3. x1 <- x # for each variable x that has an active binding and that you want to save

  4. rm(x, pos=1)

  5. save.image() # to overwrite the old saved .RData file (only works with position 1)

If the inactive tracked environment is at a position other than 1 on the search list, substitute the appropriate position for 1 in the above.

Author(s)

Tony Plate tplate@acm.org

See Also

Overview and design of the track package.

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
##############################################################
# Warning: running this example will cause variables currently
# in the R global environment to be written to .RData files
# in a tracking database on the filesystem under R's temporary
# directory, and will cause the variables to be removed temporarily
# from the R global environment.
# It is recommended to run this example with a fresh R session
# with no important variables in the global environment.
##############################################################

library(track)
track.start(dir=file.path(tempdir(), 'rdatadir4'))
x <- 33
X <- array(1:24, dim=2:4)
Y <- list(a=1:3,b=2)
X[2] <- -1
track.datadir(relative=TRUE)
track.datadir(relative=FALSE)
track.filename(list=c("x", "X"))
track.info()
track.mem()
env.is.tracked(pos=1)
env.is.tracked(pos=2)
# Would normally not call track.stop(), but do so here to clean up after
# running this example.
track.stop(pos=1, keepVars=TRUE)

track documentation built on May 2, 2019, 10:22 a.m.