Skip to contents

Import a Viva Insights Query from a .csv file, with variable classifications optimised for other functions in the package.

Usage

import_query(
  x,
  pid = NULL,
  dateid = NULL,
  date_format = "%m/%d/%Y",
  convert_date = TRUE,
  encoding = "UTF-8"
)

Arguments

x

String containing the path to the Viva Insights query to be imported. The input file must be a .csv file, and the file extension must be explicitly entered, e.g. "/files/standard query.csv"

pid

String specifying the unique person or individual identifier variable. import_query renames this to PersonId so that this is compatible with other functions in the package. Defaults to NULL, where no action is taken.

dateid

String specifying the date variable. import_query renames this to MetricDate so that this is compatible with other functions in the package. Defaults to NULL, where no action is taken.

date_format

String specifying the date format for converting any variable that may be a date to a Date variable. Defaults to "%m/%d/%Y".

convert_date

Logical. Defaults to TRUE. When set to TRUE, any variable that matches true with is_date_format() gets converted to a Date variable. When set to FALSE, this step is skipped.

encoding

String to specify encoding to be used within data.table::fread(). See data.table::fread() documentation for more information. Defaults to 'UTF-8'.

Value

A tibble is returned.

Details

import_query() uses data.table::fread() to import .csv files for speed, and by default stringsAsFactors is set to FALSE. A data frame is returned by the function (not a data.table). Column names are automatically cleaned, replacing spaces and special characters with underscores.

See also

Other Import and Export: copy_df(), create_dt(), export()