compareLengths {Ecfun} R Documentation

## Compare the lengths of two objects

### Description

Issue a warning or error if the lengths of two objects are not compatible.

### Usage

compareLengths(x, y,
name.x=deparse(substitute(x), width.cutoff,
nlines=1, ...),
name.y=deparse(substitute(y), width.cutoff,
nlines=1, ...),
message0='', compFun=c('NROW', 'length'),
action=c(compatible='', incompatible='warning'),
length0=c('compatible', 'incompatible', 'stop'),
width.cutoff=20, ...)


### Arguments

 x, y objects whose lengths are to be compared name.x, name.y names of x and y to use in a message. Default = deparse(substitute(.), width.cutoff, nlines=1). message0 character string to be included with name.x and name.y in a message. compFun function to use in the comparison. action A character vector of length 2 giving the names of functions to call if the lengths are not equal but are either 'compatible' or 'incompatible'; ” means no action. length0 If length(x) or length(y) = 0 (but not both), treat this case as specified by length0. width.cutoff width.cutoff argument to pass to deparse. This gives the maximum number of characters to use in a name in error and warning messages. ... optional arguments for deparse

### Details

1. If nchar(name.x) = 0 = nchar(name.y), set name.x <- 'x', name.y <- 'y', and append 'in compareLengths:' to message0 for more informative messaging.

2. lenx <- do.call(compFun, list(x)); leny <- do.call(compFun, list(y))

3. if(lenx==leny)return(c('equal', ''))

4. Compatible?

5. Compose the message.

6. "action", as indicated

### Value

A character vector of length 2. The first element is either 'equal', 'compatible' or 'incompatible'. The second element is the message composed.

### Author(s)

Spencer Graves with help from Duncan Murdoch

interpChar

### Examples

##
## 1.  equal
##

all.equal(compareLengths(1:3, 4:6), c("equal", ''))

##
## 2.  compatible
##
a <- 1:2
b <- letters[1:6]
comp.ab <- compareLengths(a, b, message0='Chk:')
comp.ba <- compareLengths(b, a, message0='Chk:')
# check
chk.ab <- c('compatible',
'Chk: length(b) = 6 is 3 times length(a) = 2')

all.equal(comp.ab, chk.ab)

all.equal(comp.ba, chk.ab)

##
## 3.  incompatible
##
Z <- LETTERS[1:3]
comp.aZ <- compareLengths(a, Z)
# check
chk.aZ <- c('incompatible',
' length(Z) = 3 is not a multiple of length(a) = 2')

all.equal(comp.aZ, chk.aZ)

##
## 4.  problems with name.x and name.y
##
comp.ab2 <- compareLengths(a, b, '', '')
# check
chk.ab2 <- c('compatible',
'in compareLengths: length(y) = 6 is 3 times length(x) = 2')

all.equal(comp.ab2, chk.ab2)

##
## 5.  zeroLength
##
zeroLen <- compareLengths(logical(0), 1)
# check
zeroL <- c('compatible', ' length(logical(0)) = 0')

all.equal(zeroLen, zeroL)



[Package Ecfun version 0.3-2 Index]
{"ft_lang_label":"__label__en","ft_lang_prob":0.5090089,"math_prob":0.96513736,"size":2292,"snap":"2023-40-2023-50","text_gpt3_token_len":708,"char_repetition_ratio":0.17788461,"word_repetition_ratio":0.012048192,"special_character_ratio":0.34293193,"punctuation_ratio":0.26035503,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97708285,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-12-08T21:53:53Z\",\"WARC-Record-ID\":\"<urn:uuid:4fae9948-d9f2-470a-a062-a92169ae7873>\",\"Content-Length\":\"5762\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:3ef33fe3-a2b4-4346-96b3-c7855fc721eb>\",\"WARC-Concurrent-To\":\"<urn:uuid:151b5d5b-b40b-4106-b5f9-6afbd149b437>\",\"WARC-IP-Address\":\"137.208.57.46\",\"WARC-Target-URI\":\"https://search.r-project.org/CRAN/refmans/Ecfun/html/compareLengths.html\",\"WARC-Payload-Digest\":\"sha1:XGVK6WS3NGOACZRWCT7CYOZLHS7I63VC\",\"WARC-Block-Digest\":\"sha1:OEHSJZ7FBBE3P6G6IKMHZU5UGSBNU5DO\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679100779.51_warc_CC-MAIN-20231208212357-20231209002357-00516.warc.gz\"}"}