regex - Print out Regular Expression Table with kable -


i trying create basic reference table in rmarkdown regular expressions, , i'm having trouble trying concatenate strings of characters together. i'm not sure if should using `` instead of "" specify these strings literally, i'm pretty stuck. seems keep getting ton of errors around syntax. appreciated. thanks.

this how table in markdown code:

 posix class name| description             |examples -------------   | ------------------------|------------------------  [:alpha:]       |alphanumeric characters  |[[:alpha:][:digit:]] or [a-z09] [:punct:]       |punctation characters    |! \ \" # $ % & '( ) * + , - . / : ;  ? @ [ \ \ ] ^ _`{ | }~ 

however, of these characters hard render in string, (such null character). below code attempting sample table in dataframe.

#create charatctor class table class_name <- c("[:alnum:]","[:alpha:]","[:ascii:]","[:blank:]","[:cntrl:]","[:digit:]","[:graph:]","[:lower:]","[:print:]", "[:punct:]","[:space:]","[:upper:]","[:xdigit:]") description <- c("alphanumeric characters","alphabetic characters","ascii characters","space , tab","control characters", "digits","visible characters (anything except spaces , control characters)","lowercase letters","visible characters , spaces (anything except control characters)","punctuation , symbols.","all whitespace characters, including line breaks", "uppercase letters","hexadecimal digits") examples <- c(`[[:alpha:][:digit:]] or [a-z0-9]`,               `[[:lower:][:upper:]] or [a-z]`,               `abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz`,               `[ \t]`,               "\nor\r,[\x\0\0-\x1f\x7f]",               `or \d: digits, 0 1 2 3 4 5 6 7 8 9, equivalent [0-9]`,               `[:alnum:] , [:punct:]`,               `[a-z]`,               `[[:alnum:][:punct:]\\s]`,               `! \ \" # $ % & '( ) * + , - . / : ; < = > ? @ [ \ \ ] ^ _`{ | }~` )  char_class <- data.frame(class_name,description,examples) names(char_class) <- c("class name","description","examples")  #view table kable(char_class, col.names = names(char_class), align = c('c','l'), caption = "character class examples") 

errors i'm getting:

error: '\x' used without hex digits in character string starting ""\nor\r,[\x" error: nul character not allowed (line 5) 

part of i'm trying put reference guide regular expressions in r, it's pretty hard print out these characters other normal markdown, i'd data in data frame if possible use kable's formatting.

any appreciated. thanks.

after replacing single backslashes (with doubled backslashes) before items not listed r specials "\n" , "\t" described in ?syntax , ?quotes , omitting last 3 of class_name , description vectors (since had no corresponding items examples vector, possible make legal r dataframe:

class_name <- c("[:alnum:]","[:alpha:]","[:ascii:]","[:blank:]","[:cntrl:]","[:digit:]","[:graph:]","[:lower:]","[:print:]", "[:punct:]","[:space:]","[:upper:]","[:xdigit:]") description <- c("alphanumeric characters","alphabetic characters","ascii characters","space , tab","control characters", "digits","visible characters (anything except spaces , control characters)","lowercase letters","visible characters , spaces (anything except control characters)","punctuation , symbols.","all whitespace characters, including line breaks", "uppercase letters","hexadecimal digits") examples <- c('[[:alpha:][:digit:]] or [a-z0-9]',               '[[:lower:][:upper:]] or [a-z]',               'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz',               '[ \t]',               "\\nor\\r,[\\x\\0\\0-\\x1f\\x7f]",               'or \\d: digits, 0 1 2 3 4 5 6 7 8 9, equivalent [0-9]',               '[:alnum:] , [:punct:]',               '[a-z]',               '[[:alnum:][:punct:]\\s]',               '! \\ \\" # $ % & \\\' ( ) * + \\, - . / : ; < = > ? @ [ ] ^ _ { | } ~ ' )  char_class <- data.frame(class_name[1:10],description[1:10],examples) names(char_class) <- c("class name","description","examples") 
#
> char_class    class name                                                        description 1   [:alnum:]                                            alphanumeric characters 2   [:alpha:]                                              alphabetic characters 3   [:ascii:]                                                   ascii characters 4   [:blank:]                                                      space , tab 5   [:cntrl:]                                                 control characters 6   [:digit:]                                                             digits 7   [:graph:] visible characters (anything except spaces , control characters) 8   [:lower:]                                                  lowercase letters 9   [:print:] visible characters , spaces (anything except control characters) 10  [:punct:]                                           punctuation , symbols.                                                                 examples 1                                       [[:alpha:][:digit:]] or [a-z0-9] 2                                          [[:lower:][:upper:]] or [a-z] 3                   abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz 4                                                                  [ \t] 5                                        \\nor\\r,[\\x\\0\\0-\\x1f\\x7f] 6               or \\d: digits, 0 1 2 3 4 5 6 7 8 9, equivalent [0-9] 7                                                [:alnum:] , [:punct:] 8                                                                  [a-z] 9                                                [[:alnum:][:punct:]\\s] 10 ! \\ \\" # $ % & \\' ( ) * + \\, - . / : ; < = > ? @ [ ] ^ _ { | } ~  

the r print function (which displaying these above) shows backslashes "\". character value of "\" contains single character, namely backslash. if display cat see character, there no cat-method items of class-"data.frame":

> print("\\") [1] "\\" > cat("\\") \ 

Comments