write_ok_selection_list: Writes the sampling plan with the selection list to an Excel...

View source: R/write_ok_selection_list.R

write_ok_selection_listR Documentation

Writes the sampling plan with the selection list to an Excel file.

Description

The sampling plan is output to an Excel sheet. The list with selected units is standardised and formatted in order to be submitted without further formatting.

Usage

write_ok_selection_list(
  data,
  sheet,
  filename,
  filepath,
  column_standards = OKplan::OK_column_standards,
  calculate_sum = TRUE,
  footnote = NULL,
  footnote_heights = NULL,
  dbsource,
  add_worksheet = FALSE,
  ...
)

Arguments

data

[data.frame]
The sampling plan with the units to be reported.

sheet

[character(1)]
The name of the Excel sheet.

filename

[character(1)]
The name of the Excel file.

filepath

[character(1)]
The path to the Excel file.

column_standards

[data.frame | list | character(1)]
The column standards to be used as input for standardize_columns when formatting the sampling plan for output, see details. Defaults to OK_column_standards. For giving alternatives to the standard table for column_standards using different formats, see details. Defaults to file.path(NVIdb::set_dir_NVI("ProgrammeringR", slash = FALSE), "standardization", "colnames", "column_standards.csv").

calculate_sum

[logical(1)]
Should a line with the sum be appended? Defaults to TRUE.

footnote

[character(1)]
Footnote to appended? Defaults to NULL.

footnote_heights

[integer(1)]
Manually set row height for the footnote. Defaults to NULL.

dbsource

[character(1)]
The name of the dbtable in OK_column_standards that should be used for standardising and formatting the sampling plan output.

add_worksheet

[logical(1)]
Should a worksheet be added to an existing workbook? Defaults to FALSE.

...

Other arguments to be passed to append_sum_line.

Details

The data must originate from an "okplan" file and the function uses NVIdb::standardize_columns. to select, order, format and style the columns. The formatting information is either taken from OK_column_standards or can be input as a list

When using OK_column_standards, the formatting information is taken in accord with the argument dbsource. If the formatting needs to be edited, it must be edited in the general source file for column standards and thereafter, build it into a new version of OKplan. As this can be a tedious process, there is a possibility to input the formatting information as a list or as a csv-file that can be transformed to a data.frame with the same columns as OK_column_standards.

The list input to column_standards must follow a specific format. It is a list with at least three named vectors:

  • colname: a vector of all columns in in the source file that should be included in the Excel report with the selection list.

  • collabel: A vector with the labels that should be used in the Excel report.

  • colwidth: A vector with the column width that should be used in the Excel report.

In addition one may input:

  • colorder: the order of the columns to be used in the Excel report. The default is to use the same order as they are entered in the vectors.

  • column_db: input added as a possibility to keep on the same format as OK_column_standards. Not necessary to input.

  • table_db: input added as a possibility to keep on the same format as OK_column_standards. Must be the same as dbsource. Not necessary to input.

All vectors must have the same order and the same length.

When calculate_sum is TRUE, a line with the sum will be appended. The default is to calculate the sum of the column "ant_prover". If the sum should be calculated for one or more other columns, you may give the column names as input to the argument column that will be passed to append_sum_line. The sum will only be appended for columns that exist in the data.

When more than one worksheet should be added to a single workbook, use add_worksheet = FALSE for the first worksheet and add_worksheet = TRUE for the consecutive worksheet(s).


NorwegianVeterinaryInstitute/OKplan documentation built on Dec. 20, 2024, 10:41 a.m.