| Title: | Read and Write Files from Egnyte |
|---|---|
| Description: | Provides functions to read and write files from Egnyte cloud storage using the Egnyte API. Supports both API key and OAuth 2.0 authentication for file transfer operations. |
| Authors: | Mike Stackhouse [aut, cre] (ORCID: <https://orcid.org/0000-0001-6030-723X>) |
| Maintainer: | Mike Stackhouse <[email protected]> |
| License: | Apache License 2.0 | file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-05-11 07:03:16 UTC |
| Source: | https://github.com/atorus-research/egnyte |
Stores Egnyte domain and API key for use in subsequent API calls.
Credentials can also be set via environment variables EGNYTE_DOMAIN
and EGNYTE_API_KEY.
eg_auth(domain, api_key)eg_auth(domain, api_key)
domain |
Your Egnyte domain (the subdomain part of yourcompany.egnyte.com) |
api_key |
Your Egnyte API key or OAuth access token |
Invisibly returns a list with the stored credentials.
## Not run: eg_auth("mycompany", "my_api_key_here") ## End(Not run)## Not run: eg_auth("mycompany", "my_api_key_here") ## End(Not run)
Returns a character vector of full file paths within the specified Egnyte directory.
eg_list(path, recursive = FALSE)eg_list(path, recursive = FALSE)
path |
The Egnyte path to the directory (e.g., "/Shared/Documents"). |
recursive |
If TRUE, recursively list files in subdirectories. Defaults to FALSE. |
A character vector of full file paths.
## Not run: # List files in a directory eg_list("/Shared/Documents") # Recursively list all files eg_list("/Shared/Documents", recursive = TRUE) ## End(Not run)## Not run: # List files in a directory eg_list("/Shared/Documents") # Recursively list all files eg_list("/Shared/Documents", recursive = TRUE) ## End(Not run)
Configures the OAuth 2.0 application credentials for Egnyte authentication. These credentials are obtained by registering your application at https://developers.egnyte.com.
eg_oauth_app( domain, client_id, client_secret, redirect_uri = "https://localhost/callback" )eg_oauth_app( domain, client_id, client_secret, redirect_uri = "https://localhost/callback" )
domain |
Your Egnyte domain (the subdomain of yourcompany.egnyte.com). |
client_id |
The API key (client ID) from your registered application. |
client_secret |
The client secret from your registered application. |
redirect_uri |
The redirect URI configured for your app in the Egnyte
developer portal. Must be HTTPS. Defaults to |
After registering at https://developers.egnyte.com, you will receive a client_id and client_secret. Your application must be approved by Egnyte before it becomes active.
Important: You must configure the same redirect_uri in your Egnyte app settings. Egnyte requires all redirect URIs to be HTTPS.
During development, your API key only works with your registered Egnyte domain. After certification, it works with all Egnyte domains.
Invisibly returns a list with the OAuth app configuration.
eg_oauth_authorize() to complete the OAuth flow.
## Not run: eg_oauth_app( domain = "mycompany", client_id = "your_client_id", client_secret = "your_client_secret", redirect_uri = "https://your-registered-redirect.com/callback" ) ## End(Not run)## Not run: eg_oauth_app( domain = "mycompany", client_id = "your_client_id", client_secret = "your_client_secret", redirect_uri = "https://your-registered-redirect.com/callback" ) ## End(Not run)
Initiates the OAuth 2.0 Authorization Code flow. This opens a browser window for the user to log in and authorize the application, then prompts for the authorization code to exchange for access tokens.
eg_oauth_authorize(scope = "Egnyte.filesystem")eg_oauth_authorize(scope = "Egnyte.filesystem")
scope |
Character vector of OAuth scopes to request. Defaults to
|
The OAuth flow:
Opens a browser to Egnyte's authorization page
User logs in (via SSO if configured) and approves access
Egnyte redirects to your configured redirect_uri with ?code=...
Copy the code from the URL and paste it when prompted
The code is exchanged for access and refresh tokens
Note: Egnyte requires HTTPS redirect URIs. After authorization, you'll
be redirected to your configured URI. Copy the code parameter from the
URL (everything after code= and before any &).
Access tokens expire after 30 days. Use eg_oauth_refresh() to obtain
a new token using the refresh token.
Invisibly returns a list containing access_token, refresh_token,
token_type, and expires_in.
eg_oauth_app() to configure the OAuth application first.
## Not run: # First set up your OAuth app eg_oauth_app("mycompany", "client_id", "client_secret", redirect_uri = "https://your-app.com/callback") # Then authorize (opens browser, prompts for code) eg_oauth_authorize() # Now you can use eg_read() and eg_write() eg_read("/Shared/Documents/file.txt", "local.txt") ## End(Not run)## Not run: # First set up your OAuth app eg_oauth_app("mycompany", "client_id", "client_secret", redirect_uri = "https://your-app.com/callback") # Then authorize (opens browser, prompts for code) eg_oauth_authorize() # Now you can use eg_read() and eg_write() eg_read("/Shared/Documents/file.txt", "local.txt") ## End(Not run)
Uses the OAuth 2.0 Resource Owner Password flow to obtain an access token directly using Egnyte credentials. This is simpler than the Authorization Code flow and doesn't require browser interaction.
eg_oauth_password(username = NULL, password = NULL)eg_oauth_password(username = NULL, password = NULL)
username |
Egnyte username. If NULL, checks the |
password |
Egnyte password. If NULL, checks the |
This flow is intended for internal applications where the user trusts the application with their credentials. The username and password are sent directly to Egnyte's token endpoint.
You must first configure the OAuth app with eg_oauth_app().
Credentials can be provided via:
Function arguments
Environment variables: EGNYTE_USERNAME, EGNYTE_PASSWORD
Interactive prompt (if running interactively and not provided)
Note: This flow does not return a refresh token. When the access token expires (after 30 days), you'll need to authenticate again.
Invisibly returns a list containing access_token and expires_in.
eg_oauth_app() to configure the OAuth application first.
## Not run: # Set up your OAuth app first eg_oauth_app("mycompany", "client_id", "client_secret") # Authenticate with username/password eg_oauth_password("myuser", "mypassword") # Or use environment variables Sys.setenv(EGNYTE_USERNAME = "myuser", EGNYTE_PASSWORD = "mypassword") eg_oauth_password() # Now you can use eg_read() and eg_write() eg_read("/Shared/Documents/file.txt", "local.txt") ## End(Not run)## Not run: # Set up your OAuth app first eg_oauth_app("mycompany", "client_id", "client_secret") # Authenticate with username/password eg_oauth_password("myuser", "mypassword") # Or use environment variables Sys.setenv(EGNYTE_USERNAME = "myuser", EGNYTE_PASSWORD = "mypassword") eg_oauth_password() # Now you can use eg_read() and eg_write() eg_read("/Shared/Documents/file.txt", "local.txt") ## End(Not run)
Uses the stored refresh token to obtain a new access token without requiring user interaction.
eg_oauth_refresh()eg_oauth_refresh()
Access tokens expire after 30 days. Call this function to obtain a new access token using the refresh token that was stored during the initial authorization.
If the refresh token is also expired or revoked (e.g., user changed
password), you will need to run eg_oauth_authorize() again.
Invisibly returns a list containing the new access_token,
refresh_token, token_type, and expires_in.
eg_oauth_authorize() for the initial authorization.
## Not run: # Refresh the access token eg_oauth_refresh() ## End(Not run)## Not run: # Refresh the access token eg_oauth_refresh() ## End(Not run)
Downloads a file from Egnyte cloud storage to a local path.
eg_read(path, destfile = NULL)eg_read(path, destfile = NULL)
path |
The Egnyte path to the file (e.g., "/Shared/Documents/file.txt"). |
destfile |
Local file path where the file will be saved. If NULL (default), the file is downloaded to a temporary file. |
The local file path (invisibly).
## Not run: # Download to a specific location eg_read("/Shared/Documents/report.pdf", "local_report.pdf") # Download to a temp file local_path <- eg_read("/Shared/Documents/data.csv") read.csv(local_path) ## End(Not run)## Not run: # Download to a specific location eg_read("/Shared/Documents/report.pdf", "local_report.pdf") # Download to a temp file local_path <- eg_read("/Shared/Documents/data.csv") read.csv(local_path) ## End(Not run)
These functions download data files from Egnyte and read them into R using the appropriate package. Each function is a thin wrapper that handles the file transfer, then delegates to the underlying reader.
eg_read_csv(path, ...) eg_read_delim(path, delim = "\t", ...) eg_read_sas(path, ...) eg_read_xpt(path, ...) eg_read_stata(path, ...) eg_read_spss(path, ...) eg_read_excel(path, sheet = NULL, ...) eg_read_rds(path)eg_read_csv(path, ...) eg_read_delim(path, delim = "\t", ...) eg_read_sas(path, ...) eg_read_xpt(path, ...) eg_read_stata(path, ...) eg_read_spss(path, ...) eg_read_excel(path, sheet = NULL, ...) eg_read_rds(path)
path |
The Egnyte path to the file (e.g., "/Shared/Data/myfile.csv"). |
... |
Additional arguments passed to the underlying read function. |
delim |
The field delimiter. Defaults to tab ( |
sheet |
Sheet to read. Either a string (sheet name) or an integer (sheet position). Defaults to the first sheet. |
Each function requires an optional package to be installed:
| Function | Package | Underlying Function |
eg_read_csv() |
readr | readr::read_csv() |
eg_read_delim() |
readr | readr::read_delim() |
eg_read_excel() |
readxl | readxl::read_excel() |
eg_read_sas() |
haven | haven::read_sas() |
eg_read_xpt() |
haven | haven::read_xpt() |
eg_read_stata() |
haven | haven::read_dta() |
eg_read_spss() |
haven | haven::read_sav() |
eg_read_rds() |
(base R) | readRDS()
|
All arguments passed through ... are forwarded to the underlying function,
so you can use any options those functions support (e.g., col_types for
readr functions, encoding for haven functions).
For tabular data: A tibble (or data frame for RDS files containing data frames).
For RDS files: The R object stored in the file.
Haven-based readers (eg_read_sas(), eg_read_xpt(), eg_read_stata(),
eg_read_spss()) return tibbles with labelled columns preserving variable
labels and formats from the source file.
eg_read() for downloading raw files without parsing
eg_write_file for writing data files to Egnyte
## Not run: # CSV files df <- eg_read_csv("/Shared/Data/mydata.csv") df <- eg_read_csv("/Shared/Data/mydata.csv", col_types = "ccn") # Delimited files df <- eg_read_delim("/Shared/Data/mydata.txt") df <- eg_read_delim("/Shared/Data/mydata.txt", delim = "|") # Excel files df <- eg_read_excel("/Shared/Data/workbook.xlsx") df <- eg_read_excel("/Shared/Data/workbook.xlsx", sheet = "Summary") # SAS files df <- eg_read_sas("/Shared/Data/mydata.sas7bdat") df <- eg_read_xpt("/Shared/Data/mydata.xpt") # Stata files df <- eg_read_stata("/Shared/Data/mydata.dta") # SPSS files df <- eg_read_spss("/Shared/Data/mydata.sav") # RDS files (any R object) obj <- eg_read_rds("/Shared/Data/model.rds") ## End(Not run)## Not run: # CSV files df <- eg_read_csv("/Shared/Data/mydata.csv") df <- eg_read_csv("/Shared/Data/mydata.csv", col_types = "ccn") # Delimited files df <- eg_read_delim("/Shared/Data/mydata.txt") df <- eg_read_delim("/Shared/Data/mydata.txt", delim = "|") # Excel files df <- eg_read_excel("/Shared/Data/workbook.xlsx") df <- eg_read_excel("/Shared/Data/workbook.xlsx", sheet = "Summary") # SAS files df <- eg_read_sas("/Shared/Data/mydata.sas7bdat") df <- eg_read_xpt("/Shared/Data/mydata.xpt") # Stata files df <- eg_read_stata("/Shared/Data/mydata.dta") # SPSS files df <- eg_read_spss("/Shared/Data/mydata.sav") # RDS files (any R object) obj <- eg_read_rds("/Shared/Data/model.rds") ## End(Not run)
Uploads a local file to Egnyte cloud storage.
eg_write(file, path, overwrite = FALSE)eg_write(file, path, overwrite = FALSE)
file |
Local path to the file to upload. |
path |
The Egnyte destination path (e.g., "/Shared/Documents/file.txt"). |
overwrite |
If FALSE (default), the upload will fail if a file already exists at the destination. Set to TRUE to replace existing files. |
The Egnyte path (invisibly).
## Not run: # Upload a file eg_write("local_report.pdf", "/Shared/Documents/report.pdf") # Overwrite an existing file eg_write("updated_data.csv", "/Shared/Data/data.csv", overwrite = TRUE) ## End(Not run)## Not run: # Upload a file eg_write("local_report.pdf", "/Shared/Documents/report.pdf") # Overwrite an existing file eg_write("updated_data.csv", "/Shared/Data/data.csv", overwrite = TRUE) ## End(Not run)
These functions write R objects to data files and upload them to Egnyte. Each function is a thin wrapper that writes to a temporary file using the appropriate package, then handles the upload.
eg_write_csv(x, path, overwrite = FALSE, ...) eg_write_delim(x, path, delim = "\t", overwrite = FALSE, ...) eg_write_xpt(x, path, overwrite = FALSE, ...) eg_write_stata(x, path, overwrite = FALSE, ...) eg_write_spss(x, path, overwrite = FALSE, ...) eg_write_excel(x, path, overwrite = FALSE, ...) eg_write_rds(x, path, overwrite = FALSE, compress = TRUE)eg_write_csv(x, path, overwrite = FALSE, ...) eg_write_delim(x, path, delim = "\t", overwrite = FALSE, ...) eg_write_xpt(x, path, overwrite = FALSE, ...) eg_write_stata(x, path, overwrite = FALSE, ...) eg_write_spss(x, path, overwrite = FALSE, ...) eg_write_excel(x, path, overwrite = FALSE, ...) eg_write_rds(x, path, overwrite = FALSE, compress = TRUE)
x |
A data frame (or R object for |
path |
The Egnyte destination path (e.g., "/Shared/Data/results.csv"). |
overwrite |
If |
... |
Additional arguments passed to the underlying write function. |
delim |
The field delimiter. Defaults to tab ( |
compress |
Compression type for RDS files. See |
Each function requires an optional package to be installed:
| Function | Package | Underlying Function |
eg_write_csv() |
readr | readr::write_csv() |
eg_write_delim() |
readr | readr::write_delim() |
eg_write_excel() |
writexl | writexl::write_xlsx() |
eg_write_xpt() |
haven | haven::write_xpt() |
eg_write_stata() |
haven | haven::write_dta() |
eg_write_spss() |
haven | haven::write_sav() |
eg_write_rds() |
(base R) | saveRDS()
|
All arguments passed through ... are forwarded to the underlying function.
Note on SAS files: Haven can only write SAS transport files (.xpt), not
native SAS data files (.sas7bdat). Transport files are compatible with SAS
and can be read back with eg_read_xpt() or haven::read_xpt().
The Egnyte path (invisibly).
eg_write() for uploading raw files without conversion
eg_read_file for reading data files from Egnyte
## Not run: # CSV files eg_write_csv(mtcars, "/Shared/Data/mtcars.csv") eg_write_csv(mtcars, "/Shared/Data/mtcars.csv", overwrite = TRUE) # Delimited files eg_write_delim(mtcars, "/Shared/Data/mtcars.tsv") eg_write_delim(mtcars, "/Shared/Data/mtcars.txt", delim = "|") # Excel files eg_write_excel(mtcars, "/Shared/Data/mtcars.xlsx") # Multiple sheets eg_write_excel( list(cars = mtcars, flowers = iris), "/Shared/Data/workbook.xlsx" ) # SAS transport files eg_write_xpt(mtcars, "/Shared/Data/mtcars.xpt") # Stata files eg_write_stata(mtcars, "/Shared/Data/mtcars.dta") # SPSS files eg_write_spss(mtcars, "/Shared/Data/mtcars.sav") # RDS files (any R object) eg_write_rds(my_model, "/Shared/Data/model.rds") eg_write_rds(large_data, "/Shared/Data/data.rds", compress = "xz") ## End(Not run)## Not run: # CSV files eg_write_csv(mtcars, "/Shared/Data/mtcars.csv") eg_write_csv(mtcars, "/Shared/Data/mtcars.csv", overwrite = TRUE) # Delimited files eg_write_delim(mtcars, "/Shared/Data/mtcars.tsv") eg_write_delim(mtcars, "/Shared/Data/mtcars.txt", delim = "|") # Excel files eg_write_excel(mtcars, "/Shared/Data/mtcars.xlsx") # Multiple sheets eg_write_excel( list(cars = mtcars, flowers = iris), "/Shared/Data/workbook.xlsx" ) # SAS transport files eg_write_xpt(mtcars, "/Shared/Data/mtcars.xpt") # Stata files eg_write_stata(mtcars, "/Shared/Data/mtcars.dta") # SPSS files eg_write_spss(mtcars, "/Shared/Data/mtcars.sav") # RDS files (any R object) eg_write_rds(my_model, "/Shared/Data/model.rds") eg_write_rds(large_data, "/Shared/Data/data.rds", compress = "xz") ## End(Not run)