Skip to contents

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

Inherited methods


Method new()

Initializes the connector for file storage.

Usage

ConnectorFS$new(path, extra_class = NULL)

Arguments

path

character Path to the file storage.

extra_class

character Extra class to assign to the new connector.


Method download_cnt()

Download content from the file storage. See also download_cnt.

Usage

ConnectorFS$download_cnt(name, file = basename(name), ...)

Arguments

name

character Name of the content to read, write, or remove. Typically the table name.

file

character Path to the file to download to or upload from

...

Additional arguments passed to the method for the individual connector.

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), ...)

Arguments

file

character Path to the file to download to or upload from

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.

Returns

invisible self.


Method create_directory_cnt()

Create a directory in the file storage. See also create_directory_cnt.

Usage

ConnectorFS$create_directory_cnt(name, ...)

Arguments

name

character The name of the directory to create

...

Additional arguments passed to the method for the individual connector.

Returns

ConnectorFS object of a newly created directory


Method remove_directory_cnt()

Remove a directory from the file storage. See also remove_directory_cnt.

Usage

ConnectorFS$remove_directory_cnt(name, ...)

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), ...)

Arguments

dir

character The path to the directory to upload

name

character The name of the directory to create

...

Additional arguments passed to the method for the individual connector.

Returns

invisible self.


Method download_directory_cnt()

Download a directory from the file storage. See also download_directory_cnt.

Usage

ConnectorFS$download_directory_cnt(name, dir = name, ...)

Arguments

name

character The name of the directory to download

dir

character The path to the directory to download

...

Additional arguments passed to the method for the individual connector.

Returns

invisible connector_object.


Method tbl_cnt()

Use dplyr verbs to interact with the tibble. See also tbl_cnt.

Usage

ConnectorFS$tbl_cnt(name, ...)

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.

Returns

A table object.


Method clone()

The objects of this class are cloneable with this method.

Usage

ConnectorFS$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

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