Introduction to sss

The sss package makes it easy to read and parse survey data in the sss (triple-s) file format.

Example

library(sss)
library(dplyr, quietly = TRUE, warn.conflicts = FALSE)

Read a survey file

dat <- read.sss("sample.sss", "sample.asc")

Display the results.

dat %>% 
  as_tibble()
#> # A tibble: 3 × 17
#>   Q1      Q2_1  Q2_2  Q2_3  Q2_4  Q2_5  Q2_6  Q2_7  Q2_8  Q2_9 Q3    Q4_1  Q4_2 
#>   <chr>  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr>
#> 1 Visit…     1     0     1     0     0     0     0     0     1 "Amu… Sher… "Oth…
#> 2 Visit…     0     1     0     0     0     0     0     0     0 "   … Nott…  <NA>
#> 3 Visit…     1     0     0     1     0     0     0     0     1 "\"M… Other "\"M…
#> # ℹ 4 more variables: Q5 <dbl>, Q6 <lgl>, Q7 <chr>, Q99 <dbl>

And view the structure of the file. Note that some columns have additional attributes with variable.labels and lable.table, e.g. Q99:

str(dat)
#> 'data.frame':    3 obs. of  17 variables:
#>  $ Q1  : chr  "Visited before within the year" "Visited before that" "Visited before within the year"
#>  $ Q2_1: num  1 0 1
#>  $ Q2_2: num  0 1 0
#>  $ Q2_3: num  1 0 0
#>  $ Q2_4: num  0 0 1
#>  $ Q2_5: num  0 0 0
#>  $ Q2_6: num  0 0 0
#>  $ Q2_7: num  0 0 0
#>  $ Q2_8: num  0 0 0
#>  $ Q2_9: num  1 0 1
#>  $ Q3  : chr  "Amusement Park                " "                              " "\"Marco's\" Restaurant          "
#>  $ Q4_1: chr  "Sherwood Forest" "Nottingham Castle" "Other"
#>  $ Q4_2: chr  "Other" NA "\"Maid Marion\" Cafe"
#>  $ Q5  : num  12 999 58
#>  $ Q6  : logi  TRUE TRUE FALSE
#>  $ Q7  : chr  "Within 3 months" "More than 1 years time" NA
#>  $ Q99 : num  1.4 0.9 0.7
#>  - attr(*, "variable.labels")= chr [1:17] "Number of visits" "Attractions visited" "Attractions visited" "Attractions visited" ...
#>  - attr(*, "label.table")=List of 8
#>   ..$ 1 : Named chr [1:3] "1" "2" "3"
#>   .. ..- attr(*, "names")= chr [1:3] "First visit" "Visited before within the year" "Visited before that"
#>   ..$ 2 : Named chr [1:6] "1" "2" "3" "4" ...
#>   .. ..- attr(*, "names")= chr [1:6] "Sherwood Forest" "Nottingham Castle" "\"Friar Tuck\" Restaurant" "\"Maid Marion\" Cafe" ...
#>   ..$ 3 : Named chr NA
#>   .. ..- attr(*, "names")= chr NA
#>   ..$ 4 : Named chr [1:6] "1" "2" "3" "4" ...
#>   .. ..- attr(*, "names")= chr [1:6] "Sherwood Forest" "Nottingham Castle" "\"Friar Tuck\" Restaurant" "\"Maid Marion\" Cafe" ...
#>   ..$ 5 : Named chr [1:2] "500" "999"
#>   .. ..- attr(*, "names")= chr [1:2] "500 or more" "Not stated"
#>   ..$ 6 : Named chr NA
#>   .. ..- attr(*, "names")= chr NA
#>   ..$ 7 : Named chr [1:3] "1" "2" "3"
#>   .. ..- attr(*, "names")= chr [1:3] "Within 3 months" "Between 3 months and 1 year" "More than 1 years time"
#>   ..$ 99: Named chr NA
#>   .. ..- attr(*, "names")= chr NA

Extract the variable labels:

attr(dat, "variable.labels")
#>  [1] "Number of visits"                  "Attractions visited"              
#>  [3] "Attractions visited"               "Attractions visited"              
#>  [5] "Attractions visited"               "Attractions visited"              
#>  [7] "Attractions visited"               "Attractions visited"              
#>  [9] "Attractions visited"               "Attractions visited"              
#> [11] "Other attractions visited"         "Two favourite attractions visited"
#> [13] "Two favourite attractions visited" "Miles travelled"                  
#> [15] "Would come again"                  "When is that most likely to be"   
#> [17] "Case weight"

And the label table for question 2:

attr(dat, "label.table")$`2`
#>         Sherwood Forest       Nottingham Castle "Friar Tuck" Restaurant 
#>                     "1"                     "2"                     "3" 
#>      "Maid Marion" Cafe           Mining museum                   Other 
#>                     "4"                     "5"                     "9"