kill: Kill objects from environments.

Description Usage Arguments Details Value

View source: R/kill.R

Description

This function has the same effect as the combination suppressWarnings and rm, but it's not just a wrapper for these functions. The problem is that for such a wrapper to work, all the arguments to this functions would have to be given as characters - in conflict with the desire for a solution where we simply can replace rm with kill. This function thus inspects it's call first, and tweaks it a bit in order to figure out what to do in order to perform the extirpation. Note that this function mainly is intended for the internal cleanup inside of functions - and that the arguments thus have been made less general than those of rm, i.e. the arguments pos and inherits are not present here.

Usage

1
kill(..., list = character(), env = sys.parent())

Arguments

...

The objects to be removed, as names (unquoted) or character strings (quoted). Other stuff can be added, but will be ignored.

list

A character vector naming objects to be removed, or a list of symbols. The default value for this argument is character(). As for the ...-argument, no warnings will be triggered if the content specified in this list doesn't exist in the environment under investigation. However, the list will be sanity-checked to see if it satisfies the formal requirements. If those requirements fails, an error will be returned. (The rationale for this is that if someone actually use the list- argument instead of ..., then they might like to have this feedback with regard to the structure of that argument.)

env

The environment to use, no default value is given - but it will select the environment from which kill was called if left unspecified.

Details

The "keep it tidy"-rule is useful when writing longer functions, as it later on might be easier to update the function at some point if only the objects needed for the remaining part of the computation is presented - and the removal of objects as soon as they no longer are needed also have the beneficial effect of freeing up memory. rm is of course the natural option to use here, but since some objects only exist under conditional statements (e.g. stuff defined inside of a if-else construction), it might once in a while happen that warnings about objects not found will be triggered from rm. This can be suppressed by using suppressWarnings, but that "clutters up the code", so that's the reason for the existence of this function.

Value

This function will remove objects from the specified environment, without triggering any warnings for those objects that did not exist in the environment. Errors will be returned if envir fails to be an environment, or if list doesn't


LAJordanger/leanRcoding documentation built on Feb. 27, 2020, 4:42 p.m.