From 6bfbec9e7c11ba4e96a2856a04a70f0706df505e Mon Sep 17 00:00:00 2001
From: jennybc It’s conceivable that cli will gain a better way of vectorization,
but this works for now. Now let’s reflect on the Below we show another way to finesse this by using a variant of
Programmatic generation of bullets
+#> [1] "{.drivepath name-squatter-mv} {cli::col_grey('<id: 1ffLw3bmeh2x-p83A7DSTZT39Wu2wMEXM>')}"
+#> [2] "{.drivepath chicken-mv-renamed.txt} {cli::col_grey('<id: 1nUhjhg-vym4XsvzWoJqSSKBAXBJaJ_Um>')}"
+#> [3] "{.drivepath name-squatter-mv} {cli::col_grey('<id: 1uO2scFVdBjbqijj6LKmg4VkqmsiDHl98>')}"
+#> [4] "{.drivepath chicken-mv-renamed.txt} {cli::col_grey('<id: 12hT4mQCaA1qTpa8JEC5pCspwSHRp31jJ>')}"
+#> [5] "{.drivepath name-squatter-mv} {cli::col_grey('<id: 1wQOQt5o6mu2qoyWQ_l_67NN1_K06lr6J>')}"
dat <- drive_find(n_max = 5)
gargle_map_cli(dat)
-#> [1] "{.drivepath name-squatter-mv} {cli::col_grey('<id: 1uO2scFVdBjbqijj6LKmg4VkqmsiDHl98>')}"
-#> [2] "{.drivepath chicken-mv-renamed.txt} {cli::col_grey('<id: 12hT4mQCaA1qTpa8JEC5pCspwSHRp31jJ>')}"
-#> [3] "{.drivepath name-squatter-mv} {cli::col_grey('<id: 1wQOQt5o6mu2qoyWQ_l_67NN1_K06lr6J>')}"
-#> [4] "{.drivepath chicken-mv-renamed.txt} {cli::col_grey('<id: 1iKe4x3Zgi1PiKukxfxybVvE3Vkn9GIlq>')}"
-#> [5] "{.drivepath name-squatter-mv} {cli::col_grey('<id: 1KzVSgiHO0UXoFBk3hepNrA6PAf9gVWjK>')}"
gargle_map_cli.dribble()
also allows a custom template,
but it’s a more complicated and less common situation than for
character
. We won’t get into that here. (I don’t consider
@@ -336,11 +336,11 @@ Programmatic generation of bullets bulletize(gargle_map_cli(dat))
))
#> Some Drive files:
+#> • name-squatter-mv <id: 1ffLw3bmeh2x-p83A7DSTZT39Wu2wMEXM>
+#> • chicken-mv-renamed.txt <id: 1nUhjhg-vym4XsvzWoJqSSKBAXBJaJ_Um>
#> • name-squatter-mv <id: 1uO2scFVdBjbqijj6LKmg4VkqmsiDHl98>
#> • chicken-mv-renamed.txt <id: 12hT4mQCaA1qTpa8JEC5pCspwSHRp31jJ>
#> • name-squatter-mv <id: 1wQOQt5o6mu2qoyWQ_l_67NN1_K06lr6J>
-#> • chicken-mv-renamed.txt <id: 1iKe4x3Zgi1PiKukxfxybVvE3Vkn9GIlq>
-#> • name-squatter-mv <id: 1KzVSgiHO0UXoFBk3hepNrA6PAf9gVWjK>
#> … and 5 more
Upload
folder <- drive_mkdir("upload-into-me-article-demo")
#> Created Drive file:
-#> • upload-into-me-article-demo <id: 1i9qaRSKlcgWW3YhFs32Gk8Wbon7exhN->
+#> • upload-into-me-article-demo <id: 1Yi6vwNMQ-HIfNnzssI9YSNJ35mj1U9C3>
#> With MIME type:
#> • application/vnd.google-apps.folder
with_drive_quiet(
@@ -187,13 +187,13 @@
Upload
#> # A dribble: 7 × 3
#> name id drive_resource
#> <chr> <drv_id> <list>
-#> 1 r_logo.jpg 1Mj_qzReGo7eeJoJ3RAdg7eu-1GA-KWLg <named list [43]>
-#> 2 r_about.html 1bkk9Qio9ZnqrUUaD188R3G3CAWOHlbCq <named list [42]>
-#> 3 imdb_latin1.csv 1vGkHgDYbmB7ETqptmciFtisaK_L971DX <named list [41]>
-#> 4 chicken.txt 1pjsW0n3Jzdi31MGsuSYTVdNadZyv65po <named list [42]>
-#> 5 chicken.pdf 1V-qpjTwq9r9fl2te7BhJd8P2x6tMH1ZQ <named list [42]>
-#> 6 chicken.jpg 1moZUbq2wlbl2UKvfFVj1_SV0BRiQv1i3 <named list [43]>
-#> 7 chicken.csv 1quBVa-divVH8bEwJ5XNDkXvzr7eT3QjY <named list [41]>
files
object returned by this
operation. files
is a list of dribbles,
one per uploaded file.Upload
#> # A dribble: 7 × 3
#> name id drive_resource
#> <chr> <drv_id> <list>
-#> 1 chicken.csv 1quBVa-divVH8bEwJ5XNDkXvzr7eT3QjY <named list [41]>
-#> 2 chicken.jpg 1moZUbq2wlbl2UKvfFVj1_SV0BRiQv1i3 <named list [43]>
-#> 3 chicken.pdf 1V-qpjTwq9r9fl2te7BhJd8P2x6tMH1ZQ <named list [41]>
-#> 4 chicken.txt 1pjsW0n3Jzdi31MGsuSYTVdNadZyv65po <named list [41]>
-#> 5 imdb_latin1.csv 1vGkHgDYbmB7ETqptmciFtisaK_L971DX <named list [41]>
-#> 6 r_about.html 1bkk9Qio9ZnqrUUaD188R3G3CAWOHlbCq <named list [41]>
-#> 7 r_logo.jpg 1Mj_qzReGo7eeJoJ3RAdg7eu-1GA-KWLg <named list [43]>
+#> 1 chicken.csv 1ZiGUlPAxVpLa_u6xIKym_FMXsdwGLRZ0 <named list [41]>
+#> 2 chicken.jpg 1474ADqqhrNiF839UkIAuM0fcLwXE8fdX <named list [43]>
+#> 3 chicken.pdf 1o4hgdfR1suD6aEiCOLGi7Oo4Fw1xRWOt <named list [41]>
+#> 4 chicken.txt 1ga_UKbOwv09-ciBHpL7jpLnGKzKol5WU <named list [41]>
+#> 5 imdb_latin1.csv 1wjU-h0KLaRGmna_tWTvpOv9jpV-PE3yO <named list [41]>
+#> 6 r_about.html 1kYoXJrj0DE_imf80QvG1PY3wxha0wehp <named list [41]>
+#> 7 r_logo.jpg 1yoycE7SrO2Y8I2hS8WP3nftSSyvW6UYe <named list [43]>
purrr::map()
that does this for us, namely
map_dfr()
.Rename
new names.
(new_names <- glue("{Sys.Date()}_{basename(local_files)}"))
-#> 2024-12-27_chicken.csv
-#> 2024-12-27_chicken.jpg
-#> 2024-12-27_chicken.pdf
-#> 2024-12-27_chicken.txt
-#> 2024-12-27_imdb_latin1.csv
-#> 2024-12-27_r_about.html
-#> 2024-12-27_r_logo.jpg
+#> 2024-12-28_chicken.csv
+#> 2024-12-28_chicken.jpg
+#> 2024-12-28_chicken.pdf
+#> 2024-12-28_chicken.txt
+#> 2024-12-28_imdb_latin1.csv
+#> 2024-12-28_r_about.html
+#> 2024-12-28_r_logo.jpg
files_dribble <- map2_dfr(files, new_names, drive_rename)
#> Original file:
-#> • chicken.csv <id: 1quBVa-divVH8bEwJ5XNDkXvzr7eT3QjY>
+#> • chicken.csv <id: 1ZiGUlPAxVpLa_u6xIKym_FMXsdwGLRZ0>
#> Has been renamed:
-#> • 2024-12-27_chicken.csv <id: 1quBVa-divVH8bEwJ5XNDkXvzr7eT3QjY>
+#> • 2024-12-28_chicken.csv <id: 1ZiGUlPAxVpLa_u6xIKym_FMXsdwGLRZ0>
#> Original file:
-#> • chicken.jpg <id: 1moZUbq2wlbl2UKvfFVj1_SV0BRiQv1i3>
+#> • chicken.jpg <id: 1474ADqqhrNiF839UkIAuM0fcLwXE8fdX>
#> Has been renamed:
-#> • 2024-12-27_chicken.jpg <id: 1moZUbq2wlbl2UKvfFVj1_SV0BRiQv1i3>
+#> • 2024-12-28_chicken.jpg <id: 1474ADqqhrNiF839UkIAuM0fcLwXE8fdX>
#> Original file:
-#> • chicken.pdf <id: 1V-qpjTwq9r9fl2te7BhJd8P2x6tMH1ZQ>
+#> • chicken.pdf <id: 1o4hgdfR1suD6aEiCOLGi7Oo4Fw1xRWOt>
#> Has been renamed:
-#> • 2024-12-27_chicken.pdf <id: 1V-qpjTwq9r9fl2te7BhJd8P2x6tMH1ZQ>
+#> • 2024-12-28_chicken.pdf <id: 1o4hgdfR1suD6aEiCOLGi7Oo4Fw1xRWOt>
#> Original file:
-#> • chicken.txt <id: 1pjsW0n3Jzdi31MGsuSYTVdNadZyv65po>
+#> • chicken.txt <id: 1ga_UKbOwv09-ciBHpL7jpLnGKzKol5WU>
#> Has been renamed:
-#> • 2024-12-27_chicken.txt <id: 1pjsW0n3Jzdi31MGsuSYTVdNadZyv65po>
+#> • 2024-12-28_chicken.txt <id: 1ga_UKbOwv09-ciBHpL7jpLnGKzKol5WU>
#> Original file:
-#> • imdb_latin1.csv <id: 1vGkHgDYbmB7ETqptmciFtisaK_L971DX>
+#> • imdb_latin1.csv <id: 1wjU-h0KLaRGmna_tWTvpOv9jpV-PE3yO>
#> Has been renamed:
-#> • 2024-12-27_imdb_latin1.csv <id: 1vGkHgDYbmB7ETqptmciFtisaK_L971DX>
+#> • 2024-12-28_imdb_latin1.csv <id: 1wjU-h0KLaRGmna_tWTvpOv9jpV-PE3yO>
#> Original file:
-#> • r_about.html <id: 1bkk9Qio9ZnqrUUaD188R3G3CAWOHlbCq>
+#> • r_about.html <id: 1kYoXJrj0DE_imf80QvG1PY3wxha0wehp>
#> Has been renamed:
-#> • 2024-12-27_r_about.html <id: 1bkk9Qio9ZnqrUUaD188R3G3CAWOHlbCq>
+#> • 2024-12-28_r_about.html <id: 1kYoXJrj0DE_imf80QvG1PY3wxha0wehp>
#> Original file:
-#> • r_logo.jpg <id: 1Mj_qzReGo7eeJoJ3RAdg7eu-1GA-KWLg>
+#> • r_logo.jpg <id: 1yoycE7SrO2Y8I2hS8WP3nftSSyvW6UYe>
#> Has been renamed:
-#> • 2024-12-27_r_logo.jpg <id: 1Mj_qzReGo7eeJoJ3RAdg7eu-1GA-KWLg>
We use purrr::map2_dfr()
to work through
files
, the list of dribbles (= Drive files), and
new_names
, the vector of new names, and row bind the
@@ -284,13 +284,13 @@
Let’s confirm that, by using map2_df2()
instead of
map2()
, we got a single dribble back, instead of a list of
one-row dribbles:
What if you wanted to get a list back, because your downstream
operations include yet more map()
ing? Then you would use
map2()
.
drive_rm(folder)
#> File deleted:
-#> • upload-into-me-article-demo <id: 1i9qaRSKlcgWW3YhFs32Gk8Wbon7exhN->
+#> • upload-into-me-article-demo <id: 1Yi6vwNMQ-HIfNnzssI9YSNJ35mj1U9C3>