make_ids: Generate randomised IDs.

View source: R/make_ids.R

make_idsR Documentation

Generate randomised IDs.

Description

A utility to create randomised IDs from an experiment database/spreadsheet.

Usage

make_ids(
  file,
  range = c(0, 0),
  format = "X.?.#",
  filetype = "auto",
  seed = 1,
  ...
)

Arguments

file

A spreadsheet file containing experimental metadata. It is important that information for individual subjects is in rows.

range

The range of ID numbers. The default will number from 1 to a maximum that is 20% more than the total number of subjects in the spreadsheet (this allows some additional subjects to be added at a later date if necessary). If you want to use a larger number of subjects in the future (which should be randomised together) or if the numbering should not start at 1, then this option can be used to override the default.

format

A string specifying the components making up the ID. See Details to learn how to customise this. The default is "X.?.#".

filetype

The filetype of the input spreadsheet. Microsoft Excel (.xlsx and .xls) and Open Document Format (.ods; as used by OpenOffice/LibreOffice for example) are supported, as are comma- and tab-delimited formats (.csv, .tsv, .tab or .txt). The default behaviour is to guess the format from the file extension. If this does not work or you know better than the machine, then this option can be used to specify the filetype.

seed

The seed used to randomise the IDs. There is no real reason that this should need to be changed, but you can if you want to.

...

Additional parameters passed to the file reader. The parameters accepted depend on the input filetype.

Details

This function creates a new spreadsheet file in the same format as the input file (note the exception about .xls below). This new file will be named as the input file with "_IDs" appended to the name.

There is no support for writing to the obsolete .xls format so the modified files from .xls input will be written as .xlsx with a message.

The label format is designed to allow for an experiment name (ideally a short abbreviation), a randomised number and a control character/checksum. Not all of these components are necessary (a minimum requirement is only the randomised number—but this is not recommended). For maximum compatibility (with R variable names and many spreadsheet tools for example), it is recommended that IDs begin with a letter rather than a number. The format uses 3 special characters:

  • ? is the randomised number. Adjacent symbols will be collapsed, but it is possible (not particularly recommended) to have the number appear multiple times.

  • @ is a control character (letters that may be ambiguously written or confused with digits are not used) that is useful as a control to distinguish easily-confused ID numbers.

  • # is a checksum character generated using the Verhoeff algorithm.

Value

Invisibly returns the randomised IDs (in the order they appear in the spreadsheet) as a character vector.

See Also

read_db, or write_db for additional information on the readable/writeable file formats.

Examples

require(idLabelR)

example_spreadsheet = system.file("extdata", "Example.txt", package = "idLabelR")
ids = make_ids(file = example_spreadsheet, format = "MyExpt.?.#")


rupertoverall/idLabelR documentation built on Aug. 27, 2023, 12:39 p.m.