filePath               package:R.utils               R Documentation

_C_o_n_s_t_r_u_c_t _t_h_e _p_a_t_h _t_o _a _f_i_l_e _f_r_o_m _c_o_m_p_o_n_e_n_t_s _a_n_d _e_x_p_a_n_d_s _W_i_n_d_o_w_s _S_h_o_r_t_c_u_t_s _a_l_o_n_g _t_h_e _p_a_t_h_n_a_m_e _f_r_o_m _r_o_o_t _t_o _l_e_a_f

_D_e_s_c_r_i_p_t_i_o_n:

     Construct the path to a file from components and expands Windows
     Shortcuts along the pathname from root to leaf.  This function is
     backward compatible with 'file.path'() when argument
     'removeUps=FALSE' and 'expandLinks="none"'.

     This function exists on all platforms, not only Windows systems.

_U_s_a_g_e:

     ## Default S3 method:
     filePath(..., fsep=.Platform$file.sep, removeUps=TRUE, expandLinks=c("none", "any", "local", "relative", "network"), mustExist=FALSE, verbose=FALSE)

_A_r_g_u_m_e_n_t_s:

     ...: Arguments to be pasted together to a file path and then be
          parsed from the root to the leaf where Windows shortcut files
          are recognized and expanded according to argument 'which' in
          each step.

    fsep: the path separator to use.

removeUps: If 'TRUE', relative paths, for instance "foo/bar/../" are
          shortend into "foo/", but also "./" are removed from the
          final pathname, if possible.

expandLinks: A 'character' string. If '"none"', Windows Shortcut files
          are ignored.  If '"local"', the absolute target on the local
          file system is used. If '"relative"', the relative target is
          used. If '"network"', the network target is used. If '"any"',
          the first the local, then the relative and finally the
          network target is searched for.

mustExist: If 'TRUE' and if the target does not exist, the original
          pathname, that is, argument 'pathname' is returned. In all
          other cases the target is returned.

 verbose: If 'TRUE', extra information is written while reading.

_D_e_t_a_i_l_s:

     If 'expandLinks==TRUE', each component, call it _parent_, in the
     absolute path is processed from the left to the right as follows:
     1. If a "real" directory of name _parent_ exists, it is followed.
     2. Otherwise, if Microsoft Windows Shortcut file with name
     _parent.lnk_ exists, it is read. If its local target exists, that
     is followed, otherwise its network target is followed. 3. If no
     valid existing directory was found in (1) or (2), the expanded
     this far followed by the rest of the pathname is returned quietly.
     4. If all of the absolute path was expanded successfully the
     expanded absolute path is returned.

_V_a_l_u_e:

     Returns a 'character' string.

_O_n _s_p_e_e_d:

     Internal 'file.exists()' is call while expanding the pathname.
     This is used to check if the exists a Windows shortcut file named
     'foo.lnk' in 'path/foo/bar'. If it does, 'foo.lnk' has to be
     followed, and in other cases 'foo' is ordinary directory. The
     'file.exists()' is unfortunately a bit slow, which is why this
     function appears slow if called many times.

_A_u_t_h_o_r(_s):

     Henrik Bengtsson (<URL: http://www.braju.com/R/>)

_S_e_e _A_l_s_o:

     'readWindowsShortcut'(). 'file.path'().

_E_x_a_m_p_l_e_s:

     # Default
     print(file.path("foo", "bar", "..", "name")) # "foo/bar/../name"

     # Shorten pathname, if possible
     print(filePath("foo", "bar", "..", "name"))  # "foo/name"
     print(filePath("foo/bar/../name"))           # "foo/name"

     # Recognize Windows Shortcut files along the path, cf. Unix soft links
     filename <- system.file("data-ex/HISTORY.LNK", package="R.utils")
     print(filename)
     filename <- filePath(filename, expandLinks="relative")
     print(filename)

     stopifnot(file.exists(filename))

