Operator to extract subsets of sq objects.

Arguments

x

[sq]
An object this function is applied to.

i, j, ...

[numeric || logical]
Indices specifying elements to extract.

Value

sq object of the same type as the input, containing extracted elements

Details

This function follows vctrs-package conventions regarding argument interpretation for indexing vectors, which are a bit stricter that normal R conventions, for example implicit argument recycling is prohibited. Subsetting of the sq object does not affect its attributes (class and alphabet of the object). Attempt to extract elements using indices not present in the object will return an error.

See also

Functions from utility module: ==.sq(), get_sq_lengths(), is.sq(), sqconcatenate

Examples

# Creating object to work on:
sq_unt <- sq(c("AHSNLVSCTK$SH%&VS", "YQTVKA&#BSKJGY",
               "IAKVGDCTWCTY&GT", "AVYI#VSV&*DVGDJCFA"))

# Subsetting using numeric vectors
# Extracting second element of the object:
sq_unt[2]
#> unt (unspecified type) sequences list:
#> [1] YQTVKA&#BSKJGY                                                          <14>

# Extracting elements from second to fourth:
sq_unt[2:4]
#> unt (unspecified type) sequences list:
#> [1] YQTVKA&#BSKJGY                                                          <14>
#> [2] IAKVGDCTWCTY&GT                                                         <15>
#> [3] AVYI#VSV&*DVGDJCFA                                                      <18>

# Extracting all elements except the third:
sq_unt[-3]
#> unt (unspecified type) sequences list:
#> [1] AHSNLVSCTK$SH%&VS                                                       <17>
#> [2] YQTVKA&#BSKJGY                                                          <14>
#> [3] AVYI#VSV&*DVGDJCFA                                                      <18>

# Extracting first and third element:
sq_unt[c(1,3)]
#> unt (unspecified type) sequences list:
#> [1] AHSNLVSCTK$SH%&VS                                                       <17>
#> [2] IAKVGDCTWCTY&GT                                                         <15>

# Subsetting using logical vectors
# Extracing first and third element:
sq_unt[c(TRUE, FALSE, TRUE, FALSE)]
#> unt (unspecified type) sequences list:
#> [1] AHSNLVSCTK$SH%&VS                                                       <17>
#> [2] IAKVGDCTWCTY&GT                                                         <15>

# Subsetting using empty vector returns all values:
sq_unt[]
#> unt (unspecified type) sequences list:
#> [1] AHSNLVSCTK$SH%&VS                                                       <17>
#> [2] YQTVKA&#BSKJGY                                                          <14>
#> [3] IAKVGDCTWCTY&GT                                                         <15>
#> [4] AVYI#VSV&*DVGDJCFA                                                      <18>

# Using NULL, on the other hand, returns empty sq:
sq_unt[NULL]
#> unt (unspecified type) sequences list of length 0