write_nordcan_statistics_tables: Write NORDCAN Statistics Tables to Zip

View source: R/write_nordcan_statistics_tables.R

write_nordcan_statistics_tablesR Documentation

Write NORDCAN Statistics Tables to Zip

Description

Write the output of nordcan_statistics_tables into a .zip file.

Usage

write_nordcan_statistics_tables_for_archive(x)

write_nordcan_statistics_tables_for_sending(x)

read_nordcan_statistics_tables(zip_file_path)

Arguments

x

⁠[list]⁠ (mandatory, no default)

list of statistics tables (data.tables) and any associated logs (character vectors)

zip_file_path

⁠[character]⁠ (mandatory, no default)

path to an existing zip file

Details

  • write_nordcan_statistics_tables_for_archive writes data.tables as .csv character vectors as .txt files and compresses them into nordcan_statistics_tables.zip in the current working directory set using nordcancore::set_global_nordcan_settings

  • write_nordcan_statistics_tables_for_sending writes data.tables as .csv and compresses them into nordcan_statistics_tables.zip in the current working directory set using nordcancore::set_global_nordcan_settings; does NOT save any logs (character vectors in x) as .txt files

  • read_nordcan_statistics_tables uncompresses a zip file and reads into R all .csv files as data.tables and .txt files as character vectors that it contained

Examples


## Not run: 
library("data.table")
td <- tempdir()
nordcancore::set_global_nordcan_settings(
  work_dir = td,
  participant_name = "Norway",
  first_year_incidence = 1953L,
  first_year_mortality = 1953L,
  first_year_region = 1953L,
  last_year_incidence = 2018L,
  last_year_mortality = 2018L,
  last_year_survival = 2018L
)


x <- list(log1 = letters, log2 = LETTERS[1:5],
          output1 = data.table::as.data.table(cars),
          output2 = data.table::as.data.table(CO2))


nordcanepistats::write_nordcan_statistics_tables_for_archive(x = x)

zip_file_path <- paste0(td, "/nordcan_statistics_tables.zip")
if (file.exists(zip_file_path)) {
  message("wrote zip file to ", deparse(zip_file_path))
  file.remove(zip_file_path)
} else {
  stop("example has failed. please notify authors")
}


## End(Not run)

## Not run: 
library("data.table")
nordcancore::set_global_nordcan_settings(
  work_dir = ".",
  participant_name = "Norway",
  first_year_incidence = 1953L,
  first_year_mortality = 1953L,
  first_year_region = 1953L,
  last_year_incidence = 2018L,
  last_year_mortality = 2018L,
  last_year_survival = 2018L
)

# log1 and log2 are NOT saved
x <- list(log1 = letters, log2 = LETTERS[1:5],
          output1 = data.table::as.data.table(cars),
          output2 = data.table::as.data.table(CO2))


write_nordcan_statistics_tables_for_sending(x = x)

## End(Not run)
## Not run: 
statistics <- read_nordcan_statistics_tables("nordcan_statistics_tables.zip")

## End(Not run)

CancerRegistryOfNorway/nordcanepistats documentation built on June 3, 2024, 5:41 p.m.