The ConnectorFS 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.
Details
We recommend using the wrapper function connector_fs()
to simplify the process of
creating an object of ConnectorFS class. It provides a more intuitive and user-friendly
approach to initialize the ConnectorFS class and its associated functionalities.
Super class
connector::Connector
-> ConnectorFS
Active bindings
path
character Path to the file storage
Methods
Method new()
Initializes the connector for file storage.
Usage
ConnectorFS$new(path, extra_class = NULL)
Method download_cnt()
Download content from the file storage. See also download_cnt.
Usage
ConnectorFS$download_cnt(name, file = basename(name), ...)
Returns
invisible connector_object.
Method upload_cnt()
Upload a file to the file storage. See also upload_cnt.
Usage
ConnectorFS$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.
Method upload_directory_cnt()
Upload a directory to the file storage. See also upload_directory_cnt.
Usage
ConnectorFS$upload_directory_cnt(dir, name = basename(dir), ...)
Returns
invisible self.
Method download_directory_cnt()
Download a directory from the file storage. See also download_directory_cnt.
Returns
invisible connector_object.
Method tbl_cnt()
Use dplyr verbs to interact with the tibble. See also tbl_cnt.
Arguments
name
character Name of the content to read, write, or remove. Typically the table name.
...
Additional arguments passed to the method for the individual connector.
Examples
# Create file storage connector
folder <- withr::local_tempdir()
cnt <- ConnectorFS$new(folder)
cnt
#> <ConnectorFS>
#> Inherits from: <Connector>
#> Registered methods:
#> • `create_directory_cnt.ConnectorFS()`
#> • `download_cnt.ConnectorFS()`
#> • `download_directory_cnt.ConnectorFS()`
#> • `list_content_cnt.ConnectorFS()`
#> • `log_read_connector.ConnectorFS()`
#> • `log_remove_connector.ConnectorFS()`
#> • `log_write_connector.ConnectorFS()`
#> • `read_cnt.ConnectorFS()`
#> • `remove_cnt.ConnectorFS()`
#> • `remove_directory_cnt.ConnectorFS()`
#> • `tbl_cnt.ConnectorFS()`
#> • `upload_cnt.ConnectorFS()`
#> • `upload_directory_cnt.ConnectorFS()`
#> • `write_cnt.ConnectorFS()`
#> Specifications:
#> • path: /tmp/RtmppxiTmW/file1fc06a8cc1f2
# You can do the same thing using wrapper function connector_fs()
cnt <- connector_fs(folder)
cnt
#> <ConnectorFS>
#> Inherits from: <Connector>
#> Registered methods:
#> • `create_directory_cnt.ConnectorFS()`
#> • `download_cnt.ConnectorFS()`
#> • `download_directory_cnt.ConnectorFS()`
#> • `list_content_cnt.ConnectorFS()`
#> • `log_read_connector.ConnectorFS()`
#> • `log_remove_connector.ConnectorFS()`
#> • `log_write_connector.ConnectorFS()`
#> • `read_cnt.ConnectorFS()`
#> • `remove_cnt.ConnectorFS()`
#> • `remove_directory_cnt.ConnectorFS()`
#> • `tbl_cnt.ConnectorFS()`
#> • `upload_cnt.ConnectorFS()`
#> • `upload_directory_cnt.ConnectorFS()`
#> • `write_cnt.ConnectorFS()`
#> Specifications:
#> • path: /tmp/RtmppxiTmW/file1fc06a8cc1f2
# List content
cnt$list_content_cnt()
#> character(0)
# Write to the connector
cnt$write_cnt(iris, "iris.rds")
#> Warning: cannot open file '/tmp/RtmppxiTmW/file1fc06a8cc1f2/iris.rds': No such file or directory
#> Error in saveRDS(x, con, version = version, refhook = refhook, ascii = text): cannot open the connection
# Check it is there
cnt$list_content_cnt()
#> character(0)
# Read the result back
cnt$read_cnt("iris.rds") |>
head()
#> Error in find_file(name, root = connector_object$path): No file found or multiple files found with the same name