R/continuity.R

Defines functions search_name_in_list overlap names get_name

Documented in get_name names overlap search_name_in_list

#' Given an entry of a scanned line of a PDF, returns the full name
#' @param person A scanned line of content from a PDF
#' @return name The name contained within the entry
#' @export
get_name <- function(person){
  if(get_prof_year(person) %in% 2009:2013){
    name = stringr::str_split(person, ",")[[1]][1] #isolate everything before the first comma
    name = stringr::str_trim(name) #remove trailing and leading spaces
  }else{
    name = stringr::str_split(person, "\\s{4}")[[1]][1] #many spaces
  }
  name = gsub("[^a-zA-z ]", "", name) #remove any non-letters from the entry
  return(name)
}

#' Returns a list of names of all people on the person-list
#' @param person_list a list of people
#' @return a list of names on person_list
names <- function(person_list){
  return(sapply(person_list, get_name))
}

#' returns a list of names of all staff that occur on two concurrent years
#' @param list1 a faculty list
#' @param list2 a faculty list
#' @return names a list of names that appear on both faculty lists
#' @export
overlap <- function(list1, list2){
  return(intersect(names(list1), names(list2)))
}

#' Looks for a name in a faculty list
#' @param name the needle
#' @param faculty the haystack
#' @return the index of the needle in the haystack
#' @export
search_name_in_list <- function(name, faculty){
  modified <- gsub("[^a-zA-z0-9 ]", "", faculty)
  return(grep(name, modified))
}
PhilBrockman/WilliamsStaff documentation built on May 9, 2017, 6:36 p.m.