asFilePath: As File Path

Description Usage Arguments Author(s) References See Also Examples

Description

Turns a character object denoting a file path into an object of class FilePath.S3.

Usage

1
asFilePath(path = ".", ensure = FALSE, strict = FALSE, ...)

Arguments

path

Signature argument. Object containing file path information.

ensure

logical. Ensure file existence (TRUE) or not (FALSE, default).

strict

logical. TRUE: path must exist and be a file; FALSE: no prior checks. If ensure = TRUE then this is automatically set to FALSE.

...

Further arguments of: asFilePath.

Author(s)

Janko Thyson janko.thyson@rappster.de

References

https://github.com/Rappster/filesystr

See Also

asFilePath-character-method

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
## Not run: 

##------------------------------------------------------------------------------
## Method: character
##------------------------------------------------------------------------------  
  
## Path //
path_0 <- file.path(tempdir(), "path/test.txt")

res <- asFilePath(path = path_0)
res
class(res)

## Strict:
try(asFilePath(path = path_0, strict = TRUE))
## --> error as 'path' does not exist yet

try(asFilePath(path = tempdir(), strict = TRUE))
## --> error as 'path' is a directory and not a file 

## Note that 'ensure' overrules 'strict':
asFilePath(path = path_0, ensure = TRUE, strict = TRUE)
file.exists(path_0)

## Clean up //
conditionalDelete(path = path_0, condition = tempdir())

##------------------------------------------------------------------------------
## Method: FilePath.S3
##------------------------------------------------------------------------------

## Path //
path_0 <- file.path(tempdir(), "path/test2.txt")

res <- asFilePath(path = asFilePath(path_0))
res
class(res)

## Strict:
try(res <- asFilePath(path = asFilePath(path_0), strict = TRUE))
## --> error as 'path' does not exist yet

## Note that 'ensure' overrules 'strict':
asFilePath(path = asFilePath(path_0), ensure = TRUE, strict = TRUE)
file.exists(path_0)

## Clean up //
conditionalDelete(path = path_0, condition = tempdir())


## End(Not run)

rappster/filesystr documentation built on May 26, 2019, 11:17 p.m.