Skip to content

Commit ee5756b

Browse files
authored
Merge pull request #72 from awasyn/operonerror
add error handling in reverse_operons
2 parents a60f11f + 9b30014 commit ee5756b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

R/reverse_operons.R

+16
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#' directional signs based on the presence of an equal sign ("=").
1111
#'
1212
#' @param prot [vector] A vector of genomic context strings to be processed.
13+
#'
14+
#' @importFrom rlang abort
1315
#'
1416
#' @return [vector] A vector of the same length as the input, where each genomic
1517
#' element is annotated with either a forward ("->") or reverse ("<-") direction,
@@ -23,7 +25,13 @@
2325
#' straightenOperonSeq(genomic_context)
2426
#'
2527
#' # Output: "A->", "B->", "*", "<-C", "<-D", "=", "E->", "F->"
28+
2629
straightenOperonSeq <- function(prot) {
30+
# Check if 'prot' is a data frame
31+
if (!is.vector(prot)) {
32+
abort("Error: 'prot' must be a vector.")
33+
}
34+
2735
w <- prot # $GenContext.orig # was 'x'
2836

2937
y <- rep(NA, length(w))
@@ -80,6 +88,8 @@ straightenOperonSeq <- function(prot) {
8088
#'
8189
#' @param prot [data.frame] A data frame containing at least a column named
8290
#' 'GenContext', which represents the genomic contexts that need to be reversed.
91+
#'
92+
#' @importFrom rlang abort
8393
#'
8494
#' @return [data.frame] The input data frame with the 'GenContext' column updated t
8595
#' o reflect the reversed operons.
@@ -94,7 +104,13 @@ straightenOperonSeq <- function(prot) {
94104
#' reversed_prot <- reverseOperonSeq(prot)
95105
#' reversed_prot
96106
#' }
107+
97108
reverseOperonSeq <- function(prot) {
109+
# Check if 'prot' is a data frame
110+
if (!is.data.frame(prot)) {
111+
abort("Error: 'prot' must be a data frame.")
112+
}
113+
98114
gencontext <- prot$GenContext
99115

100116
gencontext <- gsub(pattern = ">", replacement = ">|", x = gencontext)

0 commit comments

Comments
 (0)