The connector_fs class is a file storage connector for accessing and manipulating files any file storage solution. The default implementation includes methods for files stored on local or network drives.
Super class
connector::connector
-> connector_fs
Active bindings
path
character Path to the file storage
Methods
Method new()
Initializes the connector for file storage.
Usage
connector_fs$new(path, extra_class = NULL)
Arguments
path
character Path to the file storage
extra_class
character Extra class to be added Checked using checkmate::assert_directory_exists.
Method download_cnt()
Download content from the file storage. See also download_cnt.
Usage
connector_fs$download_cnt(name, file = basename(name), ...)
Returns
invisible file
Method upload_cnt()
Upload a file to the file storage. See also upload_cnt.
Usage
connector_fs$upload_cnt(file, name = basename(file), ...)
Returns
invisible self.
Method create_directory_cnt()
Create a directory in the file storage. See also create_directory_cnt.
Arguments
name
character The name of the directory to create
...
Additional arguments passed to the method for the individual connector.
Method remove_directory_cnt()
Remove a directory from the file storage. See also remove_directory_cnt.
Arguments
name
character The name of the directory to remove
...
Additional arguments passed to the method for the individual connector.
Returns
invisible self.
Examples
# Create file storage connector
cnt <- connector_fs$new(tempdir())
cnt
#> <connector_fs>
#> Inherits from: <connector>
#> Registered methods:
#> • `create_directory_cnt.connector_fs()`
#> • `download_cnt.connector_fs()`
#> • `list_content_cnt.connector_fs()`
#> • `read_cnt.connector_fs()`
#> • `remove_cnt.connector_fs()`
#> • `remove_directory_cnt.connector_fs()`
#> • `upload_cnt.connector_fs()`
#> • `write_cnt.connector_fs()`
#> Specifications:
#> • path: /tmp/RtmppXBEtZ
# List content
cnt$list_content_cnt()
#> [1] "bslib-9f68e11c24c13beda8ab56edec83b1cf"
#> [2] "downlit"
#> [3] "file203d297606d1"
#> [4] "file203d3606efd7"
#> [5] "file203d3beb2288"
#> [6] "file203d69e8380a"
#> [7] "repos_https%3A%2F%2Fpackagemanager.posit.co%2Fcran%2F__linux__%2Fnoble%2Flatest%2Fsrc%2Fcontrib.rds"
# Write to the connector
cnt$write_cnt(iris, "iris.rds")
# Check it is there
cnt$list_content_cnt()
#> [1] "bslib-9f68e11c24c13beda8ab56edec83b1cf"
#> [2] "downlit"
#> [3] "file203d297606d1"
#> [4] "file203d3606efd7"
#> [5] "file203d3beb2288"
#> [6] "file203d69e8380a"
#> [7] "iris.rds"
#> [8] "repos_https%3A%2F%2Fpackagemanager.posit.co%2Fcran%2F__linux__%2Fnoble%2Flatest%2Fsrc%2Fcontrib.rds"
# Read the result back
cnt$read_cnt("iris.rds") |>
head()
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1 5.1 3.5 1.4 0.2 setosa
#> 2 4.9 3.0 1.4 0.2 setosa
#> 3 4.7 3.2 1.3 0.2 setosa
#> 4 4.6 3.1 1.5 0.2 setosa
#> 5 5.0 3.6 1.4 0.2 setosa
#> 6 5.4 3.9 1.7 0.4 setosa