Function to export data from R as a formatted .xlsx-file, distributed over multiple worksheets based on a grouping variable (e.g., year).

splitXLSX(
  file,
  data,
  sheetvar,
  title = NULL,
  source = NULL,
  metadata = NULL,
  grouplines = NULL,
  group_names = NULL,
  logo = NA,
  contactdetails = NA,
  homepage = NA,
  author = "user",
  config = "default"
)

Arguments

file

file name of the xlsx-file. The extension ".xlsx" is added

data

data to be included.

sheetvar

name of the variable used to split the data and spread them over several sheets.

title

title to be put above the data.

source

source of the data. Default can be adjusted via user profiles

metadata

metadata information to be included. Defaults to NA, meaning no metadata are attached.

grouplines

Can be used to visually group variables. Values should either correspond to numeric column indices or column names, denoting the first variable in a group. Defaults to NA, meaning no lines are added.

group_names

A vector of names for groups to be displayed in a secondary header. Should be of the same length as grouplines, and cannot be used unless these are set. Defaults to NA, meaning no secondary header is created.

logo

File path to the logo to be included in the index-sheet. Defaults to the logo of the Statistical Office of Kanton Zurich. This can either be overridden with a path to an image file, or configured in a user profile.

contactdetails

Character vector with contact information to be displayed on the title sheet. By default uses inputHelperContactInfo() to construct it based on values defined in the active user configuration.

homepage

Homepage of data publisher. Default can be adjusted via user configuration.

author

defaults to the last two letters (initials) or numbers of the internal user name.

config

which config file should be used. Default: default

Note

User should make sure that the grouping variable is of binary, categorical or other types with a limited number of levels.

Examples

if (FALSE) {
splitXLSX(file = tempfile(fileext = ".xlsx"),
          data = mtcars,
          sheetvar = "cyl",
          title = "Motor trend car road tests",
          source = paste("Source: Henderson and Velleman (1981),",
                         "Building multiple regression models interactively.",
                         "Biometrics, 37, 391–411."),
          metadata = paste("The data was extracted from the 1974 Motor Trend",
                           "US magazine and comprises fuel consumption and",
                           "10 aspects of automobile design and performance",
                           "for 32 automobiles (1973–74 models)."))
}