boxr, you will need to use a Box-app. You can think of a Box-app as the door through which the
boxr functions will access Box.
If you have access to
client_secret for a Box-app, you can use
box_auth() to authenticate:
box_auth(client_id = "your_client_id", client_secret = "your_client_secret")
This will kick off a process that, all being well, will keep you authenticated for the rest of the R session. By saving this information to your
.Renviron file, at your next R session you can use:
If you don’t have access to
client_secret for a Box-app, read on.
There are two different types of apps, as described in this overview article, or in these specific articles:
Functions that operate on Box files or directories (folders) have arguments:
dir_id. You can use the box.com web interface to find these values. Although they look like numbers, it is useful to think of them as character strings.
Directories are identified using a
We should note that the words “directory” and “folder” are used interchangeably, which can be confusing. Box uses the term “folder”, while the R world seems to favor the term “directory”. We assume that you have more familiarity with R than with Box; thus we also favor the term “directory” to name functions and arguments. We also recognize that we are not fully consistent in our implementation.
These functions all take (or return) a
box_getwd(): set and get the default working directory on Box.
box_dir_create(): create a Box directory.
box_ls(): list the files in a Box directory.
Cloud storage services can complement version control systems for code, which aren’t well suited to large binary files (e.g. databases, .RData, or heaps of pdfs). Box explicitly versions binary files, keeping old ones, and making it easy fall back to an older copy.
boxr provides git style facilities to upload, download, and synchronize the contents of entire local and remote directories. The Box API does not support this directly, so boxr loops recursively through directory structures.
box_push(): update your Box directory with new/changed local files.
box_fetch(): update your local directory with new/changed Box files.
For these functions, be sure to pay attention to these arguments:
Disclaimer: Box is not a replacement for a VCS/remote-database, and familiar verbs are no guarantee of expected behavior! Do check the function documentation before jumping in.
The advanced operations have a similar philosophy to the basic operations, most of these functions take a
file_id or a
boxr’s functions have been designed to be ‘pipeable’. Here’s a little example:
library(boxr) library(dplyr) # 'nycflights13.json' is the same as nycflights13::flights, if you want to # follow along at home box_auth() box_search("nycflights13.json") %>% # Find a remote file box_read() %>% # Download it as a data.frame group_by(origin, dest, month) %>% # Do some, er, cutting edge summarise(mu = mean(arr_delay), n = n()) %>% # analysis with dplyr! box_write("delay_summary.xlsx") %>% # Convert to .xlsx, upload box_add_description("Check out these averages!") # Add a description to your file!
If you find anything that looks like a bug while using it, please report it using a GitHub issue: https://github.com/r-box/boxr/issues.