File tree Expand file tree Collapse file tree 1 file changed +5
-15
lines changed Expand file tree Collapse file tree 1 file changed +5
-15
lines changed Original file line number Diff line number Diff line change @@ -60,30 +60,20 @@ root <- rprojroot::is_r_package
6060The ` root ` object contains a function that helps locating files below the root
6161of your package, regardless of your current working directory.
6262If you are sure that your working directory is somewhere below your project's root,
63- use the ` root$find_file() ` function:
63+ use the ` root$find_file() ` function.
64+ In this example here, we're starting in the ` vignettes ` subdirectory and find the original ` DESCRIPTION ` file:
6465
6566``` {r}
67+ basename(getwd())
6668readLines(root$find_file("DESCRIPTION"), 3)
6769```
6870
69- This works identically when starting from a subdirectory:
70-
71- ``` {r}
72- withr::with_dir(
73- "R",
74- readLines(root$find_file(path, "DESCRIPTION"), 3)
75- )
76- ```
77-
7871There is one exception: if the first component passed to ` find_file() ` is already an absolute path.
7972This allows safely applying this function to paths that may be absolute or relative:
8073
8174``` {r}
82- path <- root_file("DESCRIPTION")
83- withr::with_dir(
84- "R",
85- readLines(root$find_file(path, "DESCRIPTION"), 3)
86- )
75+ path <- root$find_file()
76+ readLines(root$find_file(path, "DESCRIPTION"), 3)
8777```
8878
8979You can also
You can’t perform that action at this time.
0 commit comments