-
Notifications
You must be signed in to change notification settings - Fork 3
/
sql_string_split.R
68 lines (63 loc) · 1.41 KB
/
sql_string_split.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#' Use SQL LEFT type function
#'
#' @description
#' Perform an SQL LEFT() type function on a piece of text
#'
#' @param .text A piece of text/string to be manipulated
#' @param .num_char How many characters do you want to grab
#'
#' @details
#' - You must supply data that you want to manipulate.
#'
#' @examples
#'
#' sql_left("text", 3)
#'
#' @export
#'
sql_left <- function(.text, .num_char) {
base::substr(.text, 1, .num_char)
}
#' Use SQL MID type function
#'
#' @description
#' Perform an SQL SUBSTRING type function
#'
#' @param .text A piece of text/string to be manipulated
#' @param .start_num What place to start at
#' @param .num_char How many characters do you want to grab
#'
#' @details
#'
#' - You must supply data that you want to manipulate.
#'
#' @examples
#'
#' sql_mid("this is some text", 6, 2)
#'
#' @export
#'
sql_mid <- function(.text, .start_num, .num_char) {
base::substr(.text, .start_num, .start_num + .num_char - 1)
}
#' Use SQL RIGHT type functions
#'
#' @description
#' Perform an SQL RIGHT type function
#'
#' @param .text A piece of text/string to be manipulated
#' @param .num_char How many characters do you want to grab
#'
#' @details
#'
#' - You must supply data that you want to manipulate.
#'
#' @examples
#'
#' sql_right("this is some more text", 3)
#'
#' @export
#'
sql_right <- function(.text, .num_char) {
base::substr(.text, base::nchar(.text) - (.num_char-1), base::nchar(.text))
}