| Cube {mstrio} | R Documentation |
Extract a MicroStrategy cube into a R Data.Frame
Description
Access, filter, publish, and extract data from MicroStrategy in-memory cubes
Create a Cube object to load basic information on a cube dataset. Specify subset of cube to be fetched through apply_filters() and clear_filters(). Fetch dataset through to_dataframe() method.
Public fields
connectionMicroStrategy connection object
cube_idIdentifier of a report.
parallelIf TRUE, downloads cube data asynchronously. FALSE by default.
nameCube name.
owner_idID of Cube owner.
pathExact path of the cube location.
last_modifiedDate of latest Cube modification.
sizeCube size.
statusCube status.
attributesCube attributes.
metricsCube metrics
attr_elementsCube attribute elements.
selected_attributesAttributes selected for filtering.
selected_metricsMetrics selected for filtering.
selected_attr_elementsAttribute elements selected for filtering.
dataframeDataframe containing data fetched from the Cube.
dataframe_listList of dataframes split to match tables in Cube.
instance_idIdentifier of an instance if cube instance has been already initialized.
Methods
Public methods
Method new()
Initialize an instance of a cube.
Usage
Cube$new(connection, cube_id, instance_id = NULL, parallel = FALSE)
Arguments
connectionMicroStrategy connection object. See Connection class.
cube_idIdentifier of a pre-existing cube containing the required data.
instance_idIdentifier of an instance if cube instance has been already initialized, NULL by default.
parallel(bool, optional): If True, utilize optimal number of threads to increase the download speed. If False (default), this feature will be disabled.
Method to_dataframe()
Extract contents of a cube into a R Data Frame.
Usage
Cube$to_dataframe(limit = NULL, multi_df = FALSE, callback = function(x, y) {
})Arguments
limit(int, optional): Used to control data extraction behaviour on cubes with a large number of rows. By default the limit is calculated automatically. If TRUE, overrides automatic limit.
multi_dfIf True (default), returns a list of dataframes resembling the table structure of the cube. If FALSE, returns one dataframe.
callbackused by the GUI to extract the progress information.
Returns
Dataframe with data fetched from the given Cube.
Method apply_filters()
Apply filters on the cube data so only the chosen attributes, metrics, and attribute elements are retrieved from the Intelligence Server.
Usage
Cube$apply_filters( attributes = NULL, metrics = NULL, attr_elements = NULL, operator = "In" )
Arguments
attributes(list or None, optional): ID numbers of attributes to be included in the filter. If list is empty, no attributes will be selected and metric data will be aggregated.
metrics(list or None, optional): ID numbers of metrics to be included in the filter. If list is empty, no metrics will be selected.
attr_elements(list or None, optional): Attributes' elements to be included in the filter.
operator(character, optional): Supported view filter operators are either "In" or "NotIn". This defines whether data will include ("In") or exclude ("NotIn") the supplied attr_elements values.
Method clear_filters()
Clear previously set filters, allowing all attributes, metrics, and attribute elements to be retrieved.
Usage
Cube$clear_filters()
Method get_attr_elements()
Load all attribute elements of the Cube. Accessible via Cube$attr_elements Fetching attriubte elements will also allow for validating attriute elements by the filter object.
Usage
Cube$get_attr_elements(limit = 50000, verbose = TRUE)
Arguments
verboseIf TRUE, displays list of attribute elements.
Method update()
Update single-table cube easily with the data frame stored in the Cube instance (cube$dataframe). Before the update, make sure that the data frame has been modified.
Usage
Cube$update(update_policy = "update")
Arguments
update_policy(character) Update operation to perform. One of 'add' (inserts new, unique rows), 'update' (updates data in existing rows and columns), 'upsert' (updates existing data and inserts new rows), or 'replace' (replaces the existing data with new data).
Method save_as()
Creates a new single-table cube with the data frame stored in the Cube instance (cube$dataframe). Before the update, make sure that the data exists.
Usage
Cube$save_as(name, description = NULL, folder_id = NULL, table_name = NULL)
Arguments
name(character): Name of the dataset. Must be less than or equal to 250 characters.
description(character, optional): Description of the dataset. Must be less than or equal to 250 characters.
folder_idID of the shared folder that the dataset should be created within. If 'None', defaults to the user's My Reports folder.
table_name(character, optional) Name of the table. If NULL, the first table name of the original cube will be used.
Method clone()
The objects of this class are cloneable with this method.
Usage
Cube$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
Examples
## Not run:
# Create a connection object.
connection = Connection$new(base_url, username, password, project_name)
# Create a cube object.
my_cube <- Cube$new(connection=conn, cube_id="...")
# See attributes and metrics in the report.
my_cube$attributes
my_cube$metrics
my_cube$attr_elements
# Specify attributes and metrics (columns) to be fetched.
my_cube$apply_filters(attributes = my_report$attributes[1:2],
metrics = my_report$metrics[1:2])
# See the selection of attributes, metrics and attribute elements.
my_cube$selected_attributes
my_cube$selected_metrics
my_cube$selected_attr_elements
# Clear filtering to load a full dataset.
my_cube$clear_filters()
# Fetch data from the Intelligence Server.
my_cube$to_dataframe()
# See the dataframe.
my_cube$dataframe
## End(Not run)