pathtopath: pathtopath combines two paths accounting for type of...

pathtopathR Documentation

pathtopath combines two paths accounting for type of separator

Description

pathtopath combines two paths, the second of which could include a filename, while taking into account the type of separator. It also prevents a doubling up or missing out of said separator between the two paths being joined. If the separator type differs between the two input paths the functions stops with a warning.

Usage

pathtopath(path1, path2)

Arguments

path1

the first path to be added together

path2

the second path which is to be added to the first. This may include a filename is so desired.

Value

the combined path

Examples

  in1 <- "c:/users/Malcolm/DropBox"
  in2 <- "aMSEUse/scenarios/EG"
  pathtopath(in1, in2)  # no separator character between the paths
  in2 <- "/aMSEUse/scenarios/EG"
  pathtopath(in1, in2)  # path2 with a separator
  in1 <- "c:/users/Malcolm/DropBox/"
  pathtopath(in1, in2)  # both paths with a separator
  in1 <- "c:\\users\\Malcolm\\DropBox"
  in2 <- "aMSEUse\\scenarios\\EG"
  pathtopath(in1, in2)  # a different separator but missing from both
  in2 <- "/aMSEUse/scenarios/EG"
  pathtopath(in1, in2)  # a different separators
  in1 <- "c:/users/Malcolm/dropbox/"
  in2 <- "aMSEUse\\scenarios\\EG"
  pathtopath(in1, in2)  # a different separators the other way around
  in2 <- "filename.csv"
  pathtopath(in1, in2)  # join path to filename that has no spearator

haddonm/codeutils documentation built on April 15, 2024, 1:02 p.m.