Learn R Programming

eye (version 1.1.0)

eyes: Count patients and eyes

Description

Counts number of patients and right and left eyes. Columns are guessed.

Usage

eyes(x, id = NULL, eye = NULL, dropunknown = TRUE)

eyestr(x, ..., english = "small", caps = FALSE)

Arguments

x

required. (data frame)

id

Patient identifying column, passed as (quoted) character

eye

Eye identifying column, passed as (quoted) character

dropunknown

introduces NA for values not recognized by recodeye

...

passed to eyes

english

Which numbers to be written in plain english: choose "small" for numbers till 12, "all" (all numbers), or "none" (or any other string!) for none

caps

if TRUE, first number will have capital first letter

Value

eyes: Named integer vector with count of patients and eyes

eyestr: Character string - can be directly pasted into reports

Guessing

id and eye arguments overrule the name guessing for the respective columns (here, cases need to match)

For any below, cases are always ignored (column names can be in upper or lower case, as you please)

patient ID columns:

  • First, eyes is looking for names that contain both strings "pat" and "id" (the order doesn't matter)

  • Next, it will look for columns that are plainly called "ID"

  • Last, it will search for all names that contain either "pat" or "id"

eye variable column:

  • eyes primarily looks for columns called either "eye" or "eyes", and if they are not present, columns containing string "eye" (e.g., EyeName will be recognized)

Eye coding

The following codes are recognized:

  • integer coding 0:1 and 1:2, right eye being the lower number.

  • right eyes: c("r", "re", "od", "right") and

  • left eyes: c("l", "le", "os", "left") and

  • both eyes: c("b", "both", "ou")

If your eye column contains other values, they will be dropped to NA (dropunknown) or kept (and then only patients will be counted, because coding remains unclear). Recommend then to recode with recodeye

eyestr

eyestr is a wrapper around eyes. It parses the result into meaningful text, which can be #' readily pasted into reports with eyes_to_string under the hood. Arguments to eyes_to_string are passed via ...:

  • small_num If TRUE (default): numbers <= 12 as words

  • UK TRUE: UK style (English) or FALSE (default): US style (American).

Examples

Run this code
# NOT RUN {
library(eyedata)
eyes(amd2)

# Examples for the usage of eyestr
eyestr(amd2)

set.seed(1)
ls_dat <-
  lapply(c(1, 12, 13),
    function(x) data.frame(id = as.character(1:x),
                           eye = sample(c("r", "l"), x, replace = TRUE)))

lapply(ls_dat, eyestr, english = "small")
lapply(ls_dat, eyestr, english = "all")
lapply(ls_dat, eyestr, english = "all", caps = TRUE)
lapply(ls_dat, eyestr, english = "none")
lapply(ls_dat, eyestr, english = "none")
# }

Run the code above in your browser using DataLab