The r-sharp script runtime environment functions
env
01 Syntax
02 Methods
| Name | Overloads | Summary |
|---|---|---|
| exit | 1 | break and force quit of current R# session without confirm |
| exists | 1 | Is an Object Defined? Look for an R object of the given name and possibly return it |
| set | 1 | Assign a Value to a Name Assign a value to a name in an environment. |
| get | 1 | Return the Value of a Named Object Search by name for an object (get) or zero or more objects (mget). |
| globalenv | 1 | Get global environment |
| environment | 1 | Get current environment or envirnment of target function closure |
| getOutputDevice | 1 | Get the standard output device name string |
| docs | 1 | Get the help document of the target runtime function |
| ls | 1 | List Objects ls and objects return a vector of character strings giving the names of the objects in the specified environment. |
| objects | 1 | list all object symbols inside current environment frame |
| objectSize | 1 | Report the Space Allocated for an Object Provides an estimate of the memory that is being used to store an R# object. |
| doCall | 1 | Execute a Function Call do.call constructs and executes a function call from a name or a function and a list of arguments to be passed to it. |
| traceback | 1 | Get and Print Call Stacks By default traceback() prints the call stack of the last uncaught error, i.e., the sequence of calls that lead to the error. |
| lockBinding | 1 | Binding and Environment Locking, Active Bindings |
| typeof | 1 | get a .NET type model from a given VB.NET type full name |
| gettype | 1 | get exported type by name |
| rm | 1 | Remove Objects from a Specified Environment remove and rm can be used to remove objects. |
| relative_work_alias | 1 | get the absolute file path that relative to the current script folder |
| relative_work | 1 | get the absolute file path that relative to the current script folder |
03 Members
Int32)break and force quit of current R# session without confirm
| Name | Type | Description |
|---|---|---|
status | Int32 | - |
String, Environment)Is an Object Defined?
Look for an R object of the given name and possibly return it
| Name | Type | Description |
|---|---|---|
name | String | a variable name (given As a character String Or a symbol). |
envir | Environment | where to look for the object (see the details section); if omitted, the function will search as if the name of the object appeared unquoted in an expression. an alternative way To specify an environment To look In, but it Is usually simpler To just use the where argument. |
Logical, true if and only if an object of the correct name and mode is found.
const myEnvir = globalenv();
if (exists(myVarName, envir = myEnvir)) { r <- get(myVarName, envir = myEnvir)
... deal with r ...
}
Assign a Value to a Name
Assign a value to a name in an environment.
There are no restrictions on the name given as x: it can be a non-syntactic name (see make.names). The pos argument can specify the environment In which To assign the Object In any Of several ways: as -1 (the default), as a positive integer (the position in the search list); as the character string name of an element in the search list; Or as an environment (including using sys.frame to access the currently active function calls). The envir argument Is an alternative way to specify an environment, but Is primarily for back compatibility. assign does Not dispatch assignment methods, so it cannot be used To Set elements Of vectors, names, attributes, etc. Note that assignment To an attached list Or data frame changes the attached copy And Not the original Object: see attach And With.
| Name | Type | Description |
|---|---|---|
env | Environment | the environment To use. See 'Details’. |
name | String | a variable name, given as a character string. No coercion is done, and the first element of a character vector of length greater than one will be used, with a warning. |
value | Object | a value To be assigned To x. |
This function is invoked for its side effect, which is assigning value to the variable x. If no envir is specified, then the assignment takes place in the currently active environment. If inherits Is TRUE, enclosing environments of the supplied environment are searched until the variable x Is encountered. The value Is Then assigned In the environment In which the variable Is encountered (provided that the binding Is Not locked: see lockBinding : If it Is, an error Is signaled). If the symbol Is Not encountered Then assignment takes place In the user's workspace (the global environment). If inherits Is FALSE, assignment takes place in the initial frame of envir, unless an existing binding Is locked Or there Is no existing binding And the environment Is locked (when an error Is signaled).
set(globalenv(), "symbol_name") <- value;
Return the Value of a Named Object
Search by name for an object (get) or zero or more objects (mget).
| Name | Type | Description |
|---|---|---|
x | Object | For get, an object name (given as a character string). For mget, a character vector of object names. |
envir | Environment | where to look for the object (see ‘Details’); if omitted search as if the name of the object appeared unquoted in an expression. |
inherits | Boolean | should the enclosing frames of the environment be searched? |
get(myVarName, envir = myEnvir)
Get global environment
| Name | Type | Description |
|---|---|---|
env | Environment | - |
Get current environment or envirnment of target function closure
| Name | Type | Description |
|---|---|---|
env | DeclareNewFunction | - |
fun | Environment | a Function, a formula, Or NULL, which Is the default. |
If fun is a function or a formula then environment(fun) returns the environment associated with that function or formula. If fun is NULL then the current evaluation environment is returned.
Get the standard output device name string
| Name | Type | Description |
|---|---|---|
env | Environment | - |
Object)Get the help document of the target runtime function
| Name | Type | Description |
|---|---|---|
x | Object | - |
String, Environment)List Objects
ls and objects return a vector of character strings giving the names of the objects in the specified environment. When invoked with no argument at the top level prompt, ls shows what data sets and functions a user has defined. When invoked with no argument inside a function, ls returns the names of the function's local variables: this is useful in conjunction with browser.
name input of the ls function:
- pattern like
package:xxxmeans get all symbols inside the specific R# package REnvmeans get all symbols inside the R# internal runtimeActivatormeans get all attached clr types full name/xxx/xxxa directory path on the file system, will list all files inside the specific directoryFunctionmeans get all attached function objects from the runtime
| Name | Type | Description |
|---|---|---|
name | String | The package name, which environment to use in listing the available objects. Defaults to the current environment. Although called name for back compatibility, in fact this argument can specify the environment in any form. |
envir | Environment | an alternative argument to name for specifying the environment. Mostly there for back compatibility. |
list all object symbols inside current environment frame
| Name | Type | Description |
|---|---|---|
env | Environment | - |
Object)Report the Space Allocated for an Object
Provides an estimate of the memory that is being used to store an R# object.
Exactly which parts of the memory allocation should be attributed to which object is not clear-cut. This function merely provides a rough indication: it should be reasonably accurate for atomic vectors, but does not detect if elements of a list are shared, for example. (Sharing amongst elements of a character vector is taken into account, but not that between character vectors in a single object.)
The calculation Is Of the size Of the Object, And excludes the space needed To store its name In the symbol table.
Associated space(e.g., the environment of a function And what the pointer in a EXTPTRSXP points to) Is Not included in the calculation.
Object sizes are larger On 64-bit builds than 32-bit ones, but will very likely be the same On different platforms With the same word length And pointer size.
| Name | Type | Description |
|---|---|---|
x | Object | an R# object. |
An object of class "object_size" with a length-one double value, an estimate of the memory allocation attributable to the object in bytes.
Execute a Function Call
do.call constructs and executes a function call from a name or a function and a list of arguments to be passed to it.
| Name | Type | Description |
|---|---|---|
what | Object | - |
calls | String | either a function or a non-empty character string naming the function to be called. |
args | Object | a list of arguments to the function call. The names attribute of args gives the argument names. |
envir | Environment | an environment within which to evaluate the call. This will be most useful if what is a character string and the arguments are symbols or quoted expressions. |
The result of the (evaluated) function call.
Object, Environment)Get and Print Call Stacks
By default traceback() prints the call stack of the last uncaught error, i.e., the sequence of calls that lead to the error. This is useful when an error occurs with an unidentifiable error message. It can also be used to print the current stack or arbitrary lists of deparsed calls.
| Name | Type | Description |
|---|---|---|
env | Object | - |
String(), Environment)Binding and Environment Locking, Active Bindings
| Name | Type | Description |
|---|---|---|
sym | String() | a name object or character string. |
env | Environment | an environment. |
String)get a .NET type model from a given VB.NET type full name
| Name | Type | Description |
|---|---|---|
fullName | String | .NET type name |
String, Environment)get exported type by name
| Name | Type | Description |
|---|---|---|
name | String | export type name |
env | Environment | - |
Remove Objects from a Specified Environment
remove and rm can be used to remove objects. These can be specified successively as character strings, or in the character vector list, or through a combination of both. All objects thus specified will be removed.
- If envir Is NULL Then the currently active environment Is searched first.
- If inherits Is TRUE Then parents Of the supplied directory are searched until a variable With the given name Is encountered. A warning Is printed For Each variable that Is Not found.
The pos argument can specify the environment from which to remove the objects in any of several ways: as an integer (the position in the search list); as the character string name of an element in the search list; or as an environment (including using sys.frame to access the currently active function calls). The envir argument is an alternative way to specify an environment, but is primarily there for back compatibility.
It Is Not allowed to remove variables from the base environment And base namespace, nor from any environment which Is locked (see lockEnvironment).
Earlier versions Of R incorrectly claimed that supplying a character vector In ... removed the objects named In the character vector, but it removed the character vector. Use the list argument To specify objects via a character vector.
| Name | Type | Description |
|---|---|---|
x | list | the objects to be removed, as names (unquoted) or character strings (quoted). |
list | Object | a character vector naming objects to be removed. |
inherits | Boolean | should the enclosing frames of the environment be inspected? |
envir | Environment | the environment to use. See ‘details’. |
get the absolute file path that relative to the current script folder
| Name | Type | Description |
|---|---|---|
file | String | this function will returns current script folder if this parameter is missing |
env | Nullable(Of Boolean) | - |
returns the given file its full path which is relative to the folder of current running script file.
get the absolute file path that relative to the current script folder
| Name | Type | Description |
|---|---|---|
file | String | this function will returns current script folder if this parameter is missing |
env | Nullable(Of Boolean) | - |
returns the given file its full path which is relative to the folder of current running script file.