R/system_usb_devices.R

Defines functions system_usb_devices

Documented in system_usb_devices

#' Function to return a system's USB devices from a \code{lsusb} system call. 
#' 
#' @author Stuart K. Grange
#' 
#' @return Tibble. 
#' 
#' @export
system_usb_devices <- function() {
  
  # Get system call
  text <- system("lsusb", intern = TRUE)
  
  # Split into variables
  text_split <- stringr::str_split_fixed(text, " ", 7)
  
  # Clean variables
  text_split[, 4] <- stringr::str_replace(text_split[, 4], ":$", "")
  text_split[, 7] <- stringr::str_trim(text_split[, 7])
  
  # Build data frame
  df <- tibble(
    bus = as.integer(text_split[, 2]), 
    device = as.integer(text_split[, 4]), 
    id = text_split[, 6], 
    description = text_split[, 7]
  )
  
  # Arrange
  df <- arrange(df, bus, device)
  
  return(df)
  
}
skgrange/systemr documentation built on April 18, 2024, 2:23 a.m.