Chapter 5 Extras

5.1 How to upload a file into Box

You can also save a new file or update an existing file directly into box. The important detail is to make sure you are working within the intended folder. First search for the folder you want:

ws <- box_search("Combined",
                 type = "folder")
ws
  Summary of first 2:

                 name   type           id   size           owner
1       Combined Data folder  *******4491  34 MB --------@nd.edu
2 Combined Clean Data folder  *******2557 6.2 MB --------@nd.edu

Then, using piping commands from the package dplyr, obtain the id for the “Combined Data” folder, and use this id as the dir_id when writing a file into box. Use the box_write() function:

## using piping commands from 'dplyr'  
ws %>%
  as.data.frame() %>%
  filter(name == "Combined Data") %>%
  select(id) %>% unlist() %>%
  box_write(dir_id = .,
            x = all_survey,
            file_name = "pilot5_merged.rds")

If file with that name already exists, boxr will attempt to upload a new version of the file.

|======================================================================| 100%
File 'pilot5_merged.rds' aleady exists. Attempting to upload new version (V9).
|======================================================================| 100%

box.com remote file reference

 name        : pilot5_merged.rds 
 file id     : *******9752 
 version     : V9 
 size        : 600 kB 
 modified at : 2020-07-17 12:24:44 
 created at  : 2020-07-17 12:24:44 
 uploaded by : --------@nd.edu 
 owned by    : --------@nd.edu 
 shared link : None 

 parent folder name :  Combined Data 
 parent folder id   :  *******4491