R/fix_path.R

Defines functions fix_path

Documented in fix_path

#' Fix a file path.
#'
#' @param path The path needing to be fixed.
fix_path <- function(
  path
){
  paths <- lapply(
    path,
    function(cpath){
      # Split the path on slashes.
      cpath <- strsplit(cpath, "/|\\\\")
      cpath <- unlist(cpath)

      # Collapse the path.
      if(length(cpath) > 1){
        out <- file.path(cpath[1], cpath[2])
      }
      if(length(cpath) >= 3){
        for(i in 3:length(cpath)){
          out <- file.path(out, cpath[i])
        }
      }
      if(length(cpath) > 1){
        cpath <- out
      }

      return(cpath)
    }
  )
  paths <- unlist(paths)

  # Return the corrected path.
  return(paths)
}

Try the documenter package in your browser

Any scripts or data that you put into this service are public.

documenter documentation built on Jan. 5, 2023, 5:11 p.m.