These function extracts all YAML fragments from all files in a directory returning a list of character vectors containing the extracted fragments.

extract_yaml_dir(
  path,
  recursive = TRUE,
  fileRegexes = c("^[^\\.]+.*$"),
  delimiterRegEx = "^---$",
  ignoreOddDelimiters = FALSE,
  encoding = "UTF-8",
  silent = TRUE
)

Arguments

path

The path containing the files.

recursive

Whether to also process subdirectories (TRUE) or not (FALSE).

fileRegexes

A vector of regular expressions to match the files against: only files matching one or more regular expressions in this vector are processed. The default regex (^[^\.]+.*$) matches all files except those that start with a period (.).

delimiterRegEx

The regular expression used to locate YAML fragments.

ignoreOddDelimiters

Whether to throw an error (FALSE) or delete the last delimiter (TRUE) if an odd number of delimiters is encountered.

encoding

The encoding to use when calling readLines(). Set to NULL to let readLines() guess.

silent

Whether to be silent (TRUE) or informative (FALSE).

Value

A list of character vectors.

Examples

### First get the directory where 'yum' is installed
yumDir <- system.file(package="yum");
### Specify the path of some example files
examplePath <- file.path(yumDir, "extdata");
### Show files (should be three .dct files)
list.files(examplePath);
#> [1] "attitude.dct"  "behavior.dct"  "intention.dct"
### Load these files
yum::extract_yaml_dir(path=examplePath);
#> $`/tmp/RtmpsqyeMl/temp_libpath80aef6b99d7d0/yum/extdata/attitude.dct`
#> [[1]]
#>  [1] "---"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
#>  [2] "dct:"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
#>  [3] "  -"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
#>  [4] "    id: attitude_71vqm37n"                                                                                                                                                                                                                                                                                                                                                                                                                                                                
#>  [5] "    label: Attitude"                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
#>  [6] "    date: 2018-12-13"                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
#>  [7] "    source:"                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
#>  [8] "      label: Reasoned Action Approach"                                                                                                                                                                                                                                                                                                                                                                                                                                                    
#>  [9] "      xdoi: ISBN"                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
#> [10] "    def:"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
#> [11] "      def: A latent definition or tendency to respond with some degree of favorableness or unfavorableness to a psychological object."                                                                                                                                                                                                                                                                                                                                                    
#> [12] "      source:"                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
#> [13] "        spec: p. 76"                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
#> [14] "    measure_dev:"                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
#> [15] "      instr: Use semantic differentials with root \"For me, [TARGET BEHAVIOR] is ...\" and a bidimensional scale where the right-most anchor expresses a good, pleasant, beneficial, or interesting evaluation and the left-most anchor expresses the opposite bad/unpleasant/harmful/boring evaluation. The dimensions that are measured can differ depending on whatever is most relevant for the target behavior (e.g. dimensions such as unfavourable-favourable could also be used)."
#> [16] "      source:"                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
#> [17] "        spec: p. 461"                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
#> [18] "    manipulate_dev:"                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
#> [19] "      instr:"                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
#> [20] "      source:"                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
#> [21] "    measure_code: "                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
#> [22] "      instr: Questionnaires that measure beneficial or pleasant aspects of the latent disposition or tendency to respond favourably versus unfavourably to [target behavior], for example using the semantic differentials good/bad, pleasant/unpleasant, wise/unwise."                                                                                                                                                                                                                   
#> [23] "      source: none"                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
#> [24] "    manipulate_code:"                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
#> [25] "      instr:"                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
#> [26] "      source:"                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
#> [27] "    aspect_code:"                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
#> [28] "      instruction: Any global evaluation of the target behavior as a whole. Note that evaluations of specific aspects or consequences of the behavior relate to aspects of underlying constructs, not of attitude itself."                                                                                                                                                                                                                                                                
#> [29] "    parentId: intention_71vr5q3q"                                                                                                                                                                                                                                                                                                                                                                                                                                                         
#> [30] "    alterId: "                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
#> [31] "---"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
#> attr(,"class")
#> [1] "yamlFragment"
#> 
#> [[2]]
#>  [1] "---"                                                                                                                                                                                                                                                                                                           
#>  [2] "dct:"                                                                                                                                                                                                                                                                                                          
#>  [3] "  -"                                                                                                                                                                                                                                                                                                           
#>  [4] "    id: attitude_instrumental_xl678lqgp"                                                                                                                                                                                                                                                                       
#>  [5] "    label: Instrumental Attitude"                                                                                                                                                                                                                                                                              
#>  [6] "    date: 2018-11-28"                                                                                                                                                                                                                                                                                          
#>  [7] "    source:"                                                                                                                                                                                                                                                                                                   
#>  [8] "      label: Reasoned Action Approach"                                                                                                                                                                                                                                                                         
#>  [9] "      id: ISBN"                                                                                                                                                                                                                                                                                                
#> [10] "    def:"                                                                                                                                                                                                                                                                                                      
#> [11] "      def: Ins Att Def"                                                                                                                                                                                                                                                                                        
#> [12] "      id: pp. 17-18"                                                                                                                                                                                                                                                                                           
#> [13] "    measure_dev:"                                                                                                                                                                                                                                                                                              
#> [14] "      instr: Use semantic differentials with root \"For me, [TARGET BEHAVIOR] is ...\" and a bidimensional scale where the right-most anchor expresses a generally desirable instrumental state/goal and the left-most anchor expresses the opposite undesirable state/goal (e.g. \"unwise\" versus \"wise\")."
#> [15] "    measure_code:"                                                                                                                                                                                                                                                                                             
#> [16] "      Bla die bla."                                                                                                                                                                                                                                                                                            
#> [17] "    manipulate_dev: "                                                                                                                                                                                                                                                                                          
#> [18] "      instr: Operationalisations that measure cognitive aspects of the latent disposition or tendency to respond favourably versus unfavourably to [target behavior], for example using the semantic differentials wise/unwise, good/bad."                                                                     
#> [19] "      source: none"                                                                                                                                                                                                                                                                                            
#> [20] "    aspect_code:"                                                                                                                                                                                                                                                                                              
#> [21] "      instr: Expressions of benefits or advantages one perceives to be caused/obtained by engaging in the target behavior."                                                                                                                                                                                    
#> [22] "      source: none"                                                                                                                                                                                                                                                                                            
#> [23] "    parentId: attitude_71vqm37n"                                                                                                                                                                                                                                                                               
#> [24] "---"                                                                                                                                                                                                                                                                                                           
#> attr(,"class")
#> [1] "yamlFragment"
#> 
#> [[3]]
#>  [1] "---"                                                                                                                                                                                                                                                                                                    
#>  [2] "dct:"                                                                                                                                                                                                                                                                                                   
#>  [3] "  -"                                                                                                                                                                                                                                                                                                    
#>  [4] "    id: attitude_experiential_xl678lqgn"                                                                                                                                                                                                                                                                
#>  [5] "    label: Experiential Attitude"                                                                                                                                                                                                                                                                       
#>  [6] "    date: 2018-11-28"                                                                                                                                                                                                                                                                                   
#>  [7] "    source:"                                                                                                                                                                                                                                                                                            
#>  [8] "      label: Reasoned Action Approach"                                                                                                                                                                                                                                                                  
#>  [9] "      id: ISBN"                                                                                                                                                                                                                                                                                         
#> [10] "    def:"                                                                                                                                                                                                                                                                                               
#> [11] "      def: Exp Att Def"                                                                                                                                                                                                                                                                                 
#> [12] "      id: pp. 15-16"                                                                                                                                                                                                                                                                                    
#> [13] "    measure_dev:"                                                                                                                                                                                                                                                                                       
#> [14] "      instr: Use semantic differentials with root \"For me, [TARGET BEHAVIOR] is ...\" and a bidimensional scale where the right-most anchor expresses a pleasant affective state and the left-most anchor expresses the opposite unpleasant affective state (e.g. \"unpleasant\" versus \"pleasant\")."
#> [15] "    manipulate_dev:"                                                                                                                                                                                                                                                                                    
#> [16] "      instr: hit one group of people with a stick and do nothing with the other group"                                                                                                                                                                                                                  
#> [17] "    measure_code: "                                                                                                                                                                                                                                                                                     
#> [18] "      instr: Operationalisations that measure affective aspects of the latent disposition or tendency to respond favourably versus unfavourably to [target behavior], for example using the semantic differentials pleasant/unpleasant, fun/boring."                                                    
#> [19] "      source: none"                                                                                                                                                                                                                                                                                     
#> [20] "    aspect_code:"                                                                                                                                                                                                                                                                                       
#> [21] "      instruction: Expressions of feelings, emotions, or affective associations that one perceives to be caused by engaging in the target behavior."                                                                                                                                                    
#> [22] "      source: none"                                                                                                                                                                                                                                                                                     
#> [23] "    parentId: attitude_71vqm37n"                                                                                                                                                                                                                                                                        
#> [24] "    alterId: affective_expectancies"                                                                                                                                                                                                                                                                    
#> [25] "---"                                                                                                                                                                                                                                                                                                    
#> attr(,"class")
#> [1] "yamlFragment"
#> 
#> attr(,"class")
#> [1] "yamlFragments" "list"         
#> 
#> $`/tmp/RtmpsqyeMl/temp_libpath80aef6b99d7d0/yum/extdata/behavior.dct`
#> [[1]]
#> [1] "---"                            "dct:"                          
#> [3] "  -"                            "    id: behavior_xl67k7w8j"    
#> [5] "    label: Behavior"            "    date: 2018-11-29"          
#> [7] "    def:"                       "      def: The target behavior"
#> [9] "---"                           
#> attr(,"class")
#> [1] "yamlFragment"
#> 
#> attr(,"class")
#> [1] "yamlFragments" "list"         
#> 
#> $`/tmp/RtmpsqyeMl/temp_libpath80aef6b99d7d0/yum/extdata/intention.dct`
#> [[1]]
#>  [1] "---"                                                                                                                                                              
#>  [2] "dct:"                                                                                                                                                             
#>  [3] "  -"                                                                                                                                                              
#>  [4] "    id: intention_71vr5q3q"                                                                                                                                       
#>  [5] "    label: Intention"                                                                                                                                             
#>  [6] "    date: 2018-12-13"                                                                                                                                             
#>  [7] "    source:"                                                                                                                                                      
#>  [8] "      name: Reasoned Action Approach"                                                                                                                             
#>  [9] "      id: ISBN"                                                                                                                                                   
#> [10] "    def:"                                                                                                                                                         
#> [11] "      def: The readiness to engage in the behavior, incorporating concepts such as willingness, behavioral expectation, and trying."                              
#> [12] "      id: pp. 43"                                                                                                                                                 
#> [13] "    measure_dev:"                                                                                                                                                 
#> [14] "      Instr: Use a likert scale to ask participants to what degree they intend to, are willing to, or plan to perform the target behavior."                       
#> [15] "      source:"                                                                                                                                                    
#> [16] "        spec: p. 463"                                                                                                                                             
#> [17] "    measure_code: "                                                                                                                                               
#> [18] "      instr: Operationalisations that measure the degree to which [target population] have a deliberate (reasoned) plan/intention to engage in [target behavior]."
#> [19] "    aspect_code:"                                                                                                                                                 
#> [20] "      instr: Any expressions that somebody has the intention, goal, or plan to perform a target behavior."                                                        
#> [21] "    parentId: behavior_xl67k7w8j"                                                                                                                                 
#> [22] "    alterId:"                                                                                                                                                     
#> [23] "---"                                                                                                                                                              
#> attr(,"class")
#> [1] "yamlFragment"
#> 
#> attr(,"class")
#> [1] "yamlFragments" "list"         
#> 
#> attr(,"class")
#> [1] "yamlFragmentsFromDir" "list"