Function for constructing relative paths in R? -
is there similar make.path.relative(base.path, target.path) ? i want convert full paths relative paths given base path (like project's directory). similar, shorter: make.path.relative = function(base, target) { common = sub('^([^|]*)[^|]*(?:\\|\\1[^|]*)$', '^\\1/?', paste0(base, '|', target)) paste0(gsub('[^/]+/?', '../', sub(common, '', base)), sub(common, '', target)) } make.path.relative('c:/home/adam', 'c:/home/adam/tmp/r') #[1] "tmp/r" make.path.relative('/home/adam/tmp', '/home/adam/documents/r') #[1] "../documents/r" make.path.relative('/home/adam/documents/r/project', '/home/adam/minetest') #[1] "../../../minetest" voodoo regex comes from here .