drive_find_path: Find folder or file along Google Drive path

View source: R/drive_find_path.R

drive_find_pathR Documentation

Find folder or file along Google Drive path

Description

Simulates Finder/File Explorer functionality by repeated calls to googledrive::drive_find(). Allows relative paths via hybrid navigation of local virtualized Google Drive for Desktop paths by going to a local lesson directory, pulling up the front-matter.yml and finding the Google ID in order to access the relative path you requested through the Drive API.

Usage

drive_find_path(
  drive_path,
  WD = NULL,
  drive_root = NULL,
  exact_match = TRUE,
  single_result = TRUE,
  checkWD = TRUE,
  raw_results = FALSE,
  ...
)

Arguments

drive_path

If you provide a dribble, it gets passed right back out. Otherwise, you can give a character string in the form "DRIVE/directory/subdirectory".

  • DRIVE can be "~" or "my drive" to refer to your private google drive (e.g. "~/Folder1/file.png")

  • Path can also be the name of a shared drive (e.g. "GP-Misc")

  • Also supports relative paths (e.g. "../meta"), as long as WD or drive_root. If WD is supplied (this is a full "local" Google Drive for Desktop path piped from pick_lesson()). If drive_root supplied, it will use that as the parent for getting relative paths.

  • Relative pathing can be significantly faster because each hierarchical call to GDrive API to resolve a folder costs about a second.

  • You can also pass an ID as a text string if you know that already

  • Generally, case SeNsItIvE...but results may vary

WD
  • a local virtualized path to a lesson folder where Google Drive (Web) path will be extracted from front matter. Easiest is to pass "?" whcih will invoke pick_lesson(); must use full_path=TRUE with pick_lesson

  • will be ignored unless relative path provided ("../folder1"), where WD will be substituted for ".."

drive_root

A Google drive path reference (not a local or virtualized path). Will be ignored unless relative path provided ("../folder1"), where drive_root will be substituted for "..". Can be:

  1. a dribble or

  2. a Googledrive ID (as a string)

  3. drive_root is passed to googledrive::drive_get()

exact_match

logical; Do you want an exact match for the file name of the path? (only applies to the final FILENAME part of the path; i.e 'folder/folder/FILENAME_w_different_suffix'); default=TRUE

single_result

logical; do you want to force a single result (i.e. throw an error if there is more than one match)?; default=TRUE

checkWD

do you want to run check_wd()? default=TRUE; set to FALSE to suppress warnings if for example you're missing teach-it.gsheet or some other item expected to be in a lesson directory

raw_results

logical; used for error checking on path resolution. If T, will export the full list of results of found paths, rather than just a tibble of the final target result. Default=FALSE

...

other arguments passed to googledrive::drive_find()

See Also

Other Google Drive Functions: drive_contents(), drive_copy_missing_files(), drive_cp_dir(), drive_get_info(), drive_inSync(), drive_new_from_template(), drive_open(), init_lesson_meta(), update_teach_links()

Examples

## Not run: 
#ABSOLUTE PATHS
#path to a drive file on your personal Google Drive
drive_find_path("~/folder_in_my_personal_drive/filename")
#path to a network drive folder
(p <- drive_find_path("GP-Studio/Edu/Lessons/geneticrescue_sci"))
#show contents of that drive folder
p %>% drive_contents()

#RELATIVE PATH to a particular lesson subfolder
#only works if you have Google Drive for Desktop set up with permissions to GP-Studio
drive_find_path("../assets",pick_lesson()) %>% drive_contents

## End(Not run)


galacticpolymath/GPpub documentation built on April 5, 2025, 6:04 p.m.