lifeTable_read: Read an Age-Stage, Two-Sex Life Table from a csv File

View source: R/lifetable_data.R

lifeTable_readR Documentation

Read an Age-Stage, Two-Sex Life Table from a csv File

Description

Reads a raw csv file containing the individual daily records of an age-stage, two-sex life table experiment and returns a life_table object, the central data structure that all other functions of the package work with.

Usage

lifeTable_read(path, check = TRUE)

Arguments

path

Character string; path to the csv file.

check

Logical; if TRUE (the default) the data are validated by lifeTable_check immediately after reading. Set to FALSE to skip validation.

Details

The csv file contains one row per individual. If the sex column is located at column n, the layout must be:

  • column 1: individual ID (header ID),

  • columns 2 to n - 2: number of days spent in each developmental stage (egg, larva, ..., pupa),

  • column n - 1: adult survival days,

  • column n: sex, coded F (female), M (male) or N (died before the adult stage),

  • columns n + 1 onward: daily oviposition of the females (one column per day; cells after the death of a female stay empty).

The first line of the file must contain the stage names as column headers, including the ID column (ID) and the sex column (gender). The sex column is located automatically by scanning the first data row for the markers F/M/N. The file encoding is detected automatically, so UTF-8 and GBK files are both supported.

Value

A life_table object; a named list with components

data

data frame with the raw csv content

file_name

file name without extension

n

column index of the sex column

n_1

n + 1, the first column of the oviposition data

n_2

n - 2, the column index of the pupal stage

header

the first row of the file (stage names), as character

encoding

the detected file encoding

path

the full path of the csv file

References

Chi, H. and Liu, H. (1985) Two new methods for study of insect population ecology. Bull. Inst. Zool. Acad. Sin 24(2), 225-240.

Chi, H. (1988) Life-table analysis incorporating both sexes and variable development rates among individuals. Environmental Entomology 17(1), 26-34.

See Also

lifeTable_check for data validation, lifeTable_calculate for the complete analysis workflow.

Examples

f <- system.file("extdata", "lifetable_example.csv", package = "insectecol")
lt <- lifeTable_read(f)
head(lt$data[, 1:5])

insectecol documentation built on Oct. 5, 2026, 5:08 p.m.