Title: | Compact Package Representations |
---|---|
Description: | A tool, grammar, and standard to represent and exchange R package source code as text files. Converts one or more source packages to a text file and restores the package structures from the file. |
Authors: | Nan Xiao [aut, cre] , Yilong Zhang [aut], Keaven Anderson [aut], Amin Shirazi [ctb], Jeff Cheng [ctb], Danfeng Fu [ctb], Merck & Co., Inc., Rahway, NJ, USA and its affiliates [cph] |
Maintainer: | Nan Xiao <[email protected]> |
License: | GPL-3 |
Version: | 0.2.4 |
Built: | 2024-11-09 21:14:03 UTC |
Source: | https://github.com/merck/pkglite |
Evaluate a list of file specifications and bind the results as a file collection.
collate(pkg = ".", ...)
collate(pkg = ".", ...)
pkg |
Path to the package directory. |
... |
One or more file specification objects. |
A file collection object containing the package name, file paths, and file format types.
The contents of this section are shown in PDF user manual only.
system.file("examples/pkg1/", package = "pkglite") %>% collate(file_default())
system.file("examples/pkg1/", package = "pkglite") %>% collate(file_default())
Common file extensions (binary)
ext_binary(flat = FALSE)
ext_binary(flat = FALSE)
flat |
Flatten the list and return a vector? |
A list or vector of standard binary file extensions.
The contents of this section are shown in PDF user manual only.
ext_binary()
ext_binary()
Common file extensions (text)
ext_text(flat = FALSE)
ext_text(flat = FALSE)
flat |
Flatten the list and return a vector? |
A list or vector of standard text file extensions.
The contents of this section are shown in PDF user manual only.
ext_text()
ext_text()
Lists all files under a folder recursively and guesses the file format type (text or binary) based on the file extension.
file_auto(path)
file_auto(path)
path |
The directory's relative path (relative to the
package root), for example, |
A list of file specifications.
The contents of this section are shown in PDF user manual only.
file_auto("inst/")
file_auto("inst/")
A default combination of common file specifications.
file_default()
file_default()
A list of file specifications.
The contents of this section are shown in PDF user manual only.
file_default()
file_default()
A combination of file specifications for eCTD submissions.
file_ectd()
file_ectd()
A list of file specifications.
The contents of this section are shown in PDF user manual only.
file_ectd()
file_ectd()
Common File name patterns
pattern_file_root_core() pattern_file_root_all() pattern_file_src() pattern_file_sanitize()
pattern_file_root_core() pattern_file_root_all() pattern_file_src() pattern_file_sanitize()
A vector of file name patterns.
The contents of this section are shown in PDF user manual only.
Specify which files to include
file_spec( path, pattern = NULL, format = c("binary", "text"), recursive = TRUE, ignore_case = TRUE, all_files = FALSE )
file_spec( path, pattern = NULL, format = c("binary", "text"), recursive = TRUE, ignore_case = TRUE, all_files = FALSE )
path |
Path relative to the package root), for example, |
pattern |
Regular expression for matching the file names. |
format |
File format type, one of |
recursive |
List files in the sub-directories? |
ignore_case |
Should pattern-matching be case-insensitive? |
all_files |
List all files including the invisible ones? |
Most of the parameters are passed through list.files()
.
A file specification object.
The contents of this section are shown in PDF user manual only.
file_spec( "R/", pattern = "\\.R$", format = "text", recursive = FALSE, ignore_case = TRUE, all_files = FALSE )
file_spec( "R/", pattern = "\\.R$", format = "text", recursive = FALSE, ignore_case = TRUE, all_files = FALSE )
file_root_core()
- core files under the package root
file_root_all()
- all files under the package root
file_r()
- files under R/
file_man()
- files under man/
file_src()
- files under src/
file_vignettes()
- files under vignettes/
file_data()
- files under data/
file_tests()
- files under tests/
file_root_core() file_root_all() file_r() file_man() file_src() file_vignettes() file_data() file_tests()
file_root_core() file_root_all() file_r() file_man() file_src() file_vignettes() file_data() file_tests()
A file specification or a list of file specifications.
The contents of this section are shown in PDF user manual only.
Is this a file collection object?
is_file_collection(object)
is_file_collection(object)
object |
Any R object. |
Logical. TRUE
if it is a file collection object,
FALSE
otherwise.
The contents of this section are shown in PDF user manual only.
system.file("examples/pkg1/", package = "pkglite") %>% collate(file_default()) %>% is_file_collection()
system.file("examples/pkg1/", package = "pkglite") %>% collate(file_default()) %>% is_file_collection()
Is this a file specification object?
is_file_spec(object)
is_file_spec(object)
object |
Any R object |
Logical. TRUE
if it is a file specification object,
FALSE
otherwise.
The contents of this section are shown in PDF user manual only.
file_spec( "R/", pattern = "\\.R$", format = "text", recursive = FALSE, ignore_case = TRUE, all_files = FALSE ) %>% is_file_spec()
file_spec( "R/", pattern = "\\.R$", format = "text", recursive = FALSE, ignore_case = TRUE, all_files = FALSE ) %>% is_file_spec()
Merge file collections
## S3 method for class 'file_collection' merge(x, y, ...)
## S3 method for class 'file_collection' merge(x, y, ...)
x |
File collection. |
y |
Another file collection. |
... |
Additional file collections. |
Merged file collection.
The contents of this section are shown in PDF user manual only.
pkg <- system.file("examples/pkg1/", package = "pkglite") fc1 <- pkg %>% collate(file_root_core()) fc2 <- pkg %>% collate(file_r(), file_man()) merge(fc1, fc2)
pkg <- system.file("examples/pkg1/", package = "pkglite") fc1 <- pkg %>% collate(file_root_core()) fc2 <- pkg %>% collate(file_r(), file_man()) merge(fc1, fc2)
Pack packages into a text file
pack(..., output, quiet = FALSE)
pack(..., output, quiet = FALSE)
... |
One or more file collection objects
generated by |
output |
Path to the output text file.
If empty, will create a txt file using the lower-cased package name
in the current working directory. For multiple packages,
will use |
quiet |
Suppress printing of progress? |
The output file path.
The contents of this section are shown in PDF user manual only.
# pack two packages pkg1 <- system.file("examples/pkg1", package = "pkglite") pkg2 <- system.file("examples/pkg2", package = "pkglite") fc1 <- pkg1 %>% collate(file_default()) fc2 <- pkg2 %>% collate(file_default()) txt <- tempfile(fileext = ".txt") pack(fc1, fc2, output = txt, quiet = TRUE) txt %>% readLines() %>% head() %>% cat(sep = "\n") txt %>% readLines() %>% length()
# pack two packages pkg1 <- system.file("examples/pkg1", package = "pkglite") pkg2 <- system.file("examples/pkg2", package = "pkglite") fc1 <- pkg1 %>% collate(file_default()) fc2 <- pkg2 %>% collate(file_default()) txt <- tempfile(fileext = ".txt") pack(fc1, fc2, output = txt, quiet = TRUE) txt %>% readLines() %>% head() %>% cat(sep = "\n") txt %>% readLines() %>% length()
Print a file collection
## S3 method for class 'file_collection' print(x, ...)
## S3 method for class 'file_collection' print(x, ...)
x |
An object of class |
... |
Additional parameters for |
The input file_collection
object.
The contents of this section are shown in PDF user manual only.
fc <- system.file("examples/pkg1/", package = "pkglite") %>% collate(file_default()) fc
fc <- system.file("examples/pkg1/", package = "pkglite") %>% collate(file_default()) fc
Print a file specification
## S3 method for class 'file_spec' print(x, ...)
## S3 method for class 'file_spec' print(x, ...)
x |
An object of class |
... |
Additional parameters for |
The input file_spec
object.
The contents of this section are shown in PDF user manual only.
fs <- file_spec( "R/", pattern = "\\.R$", format = "text", recursive = FALSE, ignore_case = TRUE, all_files = FALSE ) fs
fs <- file_spec( "R/", pattern = "\\.R$", format = "text", recursive = FALSE, ignore_case = TRUE, all_files = FALSE ) fs
Remove files from a file collection
prune(x, path) ## S3 method for class 'file_collection' prune(x, path)
prune(x, path) ## S3 method for class 'file_collection' prune(x, path)
x |
File collection. |
path |
Character vector. Relative paths of the files to remove. |
Pruned file collection.
The contents of this section are shown in PDF user manual only.
system.file("examples/pkg1/", package = "pkglite") %>% collate(file_default()) %>% prune(path = c("NEWS.md", "man/figures/logo.png"))
system.file("examples/pkg1/", package = "pkglite") %>% collate(file_default()) %>% prune(path = c("NEWS.md", "man/figures/logo.png"))
Remove content lines from a pkglite file
remove_content(input, x, quiet = FALSE)
remove_content(input, x, quiet = FALSE)
input |
Path to the text file. |
x |
A character vector. Exactly matched lines in the file content will be removed. |
quiet |
Suppress printing of progress? |
The input file path.
The contents of this section are shown in PDF user manual only.
pkg <- system.file("examples/pkg1", package = "pkglite") txt <- tempfile(fileext = ".txt") pkg %>% collate(file_default()) %>% pack(output = txt, quiet = TRUE) %>% remove_content(c("## New Features", "## Improvements"), quiet = TRUE)
pkg <- system.file("examples/pkg1", package = "pkglite") txt <- tempfile(fileext = ".txt") pkg %>% collate(file_default()) %>% pack(output = txt, quiet = TRUE) %>% remove_content(c("## New Features", "## Improvements"), quiet = TRUE)
Remove commonly excluded files from a file collection.
sanitize(x) ## S3 method for class 'file_collection' sanitize(x)
sanitize(x) ## S3 method for class 'file_collection' sanitize(x)
x |
File collection. |
Sanitized file collection.
The contents of this section are shown in PDF user manual only.
system.file("examples/pkg1/", package = "pkglite") %>% collate(file_default()) %>% sanitize()
system.file("examples/pkg1/", package = "pkglite") %>% collate(file_default()) %>% sanitize()
Remove commonly excluded files from a file collection.
sanitize_file_collection(x)
sanitize_file_collection(x)
x |
File collection. |
Sanitized file collection.
The contents of this section are shown in PDF user manual only.
system.file("examples/pkg1/", package = "pkglite") %>% collate(file_default()) %>% sanitize()
system.file("examples/pkg1/", package = "pkglite") %>% collate(file_default()) %>% sanitize()
Unpack packages from a text file
unpack(input, output = ".", install = FALSE, quiet = FALSE, ...)
unpack(input, output = ".", install = FALSE, quiet = FALSE, ...)
input |
Path to the text file. |
output |
Path to the output directory. Each package is placed under a subdirectory named after the package name. Default is the current working directory. |
install |
Try install the unpacked package(s)? |
quiet |
Suppress printing of progress? |
... |
Additional parameters for |
If install = TRUE
, the packages will be installed by the order of
appearance in the input
file. When internal dependencies exist between
these packages, make sure they are packed in the order where the
low-level dependencies appear first.
The output directory path.
The contents of this section are shown in PDF user manual only.
# pack two packages pkg1 <- system.file("examples/pkg1", package = "pkglite") pkg2 <- system.file("examples/pkg2", package = "pkglite") fc1 <- pkg1 %>% collate(file_default()) fc2 <- pkg2 %>% collate(file_default()) txt <- tempfile(fileext = ".txt") pack(fc1, fc2, output = txt, quiet = TRUE) # unpack the two packages out <- file.path(tempdir(), "twopkgs") txt %>% unpack(output = out, quiet = TRUE) out %>% file.path("pkg1") %>% list.files() out %>% file.path("pkg2") %>% list.files()
# pack two packages pkg1 <- system.file("examples/pkg1", package = "pkglite") pkg2 <- system.file("examples/pkg2", package = "pkglite") fc1 <- pkg1 %>% collate(file_default()) fc2 <- pkg2 %>% collate(file_default()) txt <- tempfile(fileext = ".txt") pack(fc1, fc2, output = txt, quiet = TRUE) # unpack the two packages out <- file.path(tempdir(), "twopkgs") txt %>% unpack(output = out, quiet = TRUE) out %>% file.path("pkg1") %>% list.files() out %>% file.path("pkg2") %>% list.files()
Check if a file contains only ASCII characters
verify_ascii(input, quiet = FALSE)
verify_ascii(input, quiet = FALSE)
input |
Path to the text file. |
quiet |
Print the elements containing non-ASCII characters? |
Logical. TRUE
if the file only contains ASCII characters,
FALSE
otherwise.
The contents of this section are shown in PDF user manual only.
pkg <- system.file("examples/pkg1", package = "pkglite") txt <- tempfile(fileext = ".txt") pkg %>% collate(file_default()) %>% pack(output = txt, quiet = TRUE) %>% verify_ascii()
pkg <- system.file("examples/pkg1", package = "pkglite") txt <- tempfile(fileext = ".txt") pkg %>% collate(file_default()) %>% pack(output = txt, quiet = TRUE) %>% verify_ascii()