library(osmdata) # fetching OpenStreetmap-data
## Data (c) OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright
library(mapview) # display interactive maps
library(stringr) # optional, tidyverse string-operations
library(dplyr)   # data-manipulation
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(sf)      # spatial features library
## Linking to GEOS 3.5.1, GDAL 2.1.2, proj.4 4.9.3
library(forcats) # 
dorset_roads <- opq(bbox = 'Dorset') %>% # set bounding box via name
  add_osm_feature(key = 'highway') %>% # get roads
  add_osm_feature(key = 'name') %>% # include the name
  osmdata_sf() # return as a sf-object
unique(dorset_roads$osm_lines$highway)
##  [1] secondary      residential    unclassified   tertiary      
##  [5] primary        trunk          track          living_street 
##  [9] trunk_link     primary_link   service        pedestrian    
## [13] footway        tertiary_link  cycleway       bridleway     
## [17] steps          path           secondary_link road          
## [21] <NA>           construction   raceway       
## 22 Levels: bridleway construction cycleway footway living_street ... unclassified
main<-unique(dorset_roads$osm_lines$highway)[c(1,3,4,5,6,9,10,14,19,20)]
dorset_roads$osm_lines %>% select(osm_id,name,highway) %>% filter(highway %in% main) %>% mapview()