Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
149 commits
Select commit Hold shift + click to select a range
6ece6a3
fixed issue with malformed json and url in air_insert funciton
collinschwantes Jul 2, 2021
06da997
added preliminary functions for using the metadata schema request fea…
collinschwantes Jul 6, 2021
f0d6e77
updated air_get to allow for subsetting by fields. This allows users …
collinschwantes Jul 6, 2021
79690f9
updated documentation to specify that fields must be given as a list
collinschwantes Jul 6, 2021
05cfc6a
added a provisional function for querying the meta data api
collinschwantes Jul 6, 2021
8ffbc82
updated package documentation
collinschwantes Jul 6, 2021
570bca3
added fetch_all to airtabl. Changed params to make them consistent wi…
collinschwantes Jul 29, 2021
0c5c1e6
moved functions from nipah bangladesh to airtabler pacakge
collinschwantes Aug 2, 2021
12d7322
added a function to get unique field values
collinschwantes Aug 2, 2021
240d5b7
explicitly named base and table_name in make json function
collinschwantes Aug 2, 2021
7eea06a
updating namespace
collinschwantes Aug 2, 2021
3b32eba
updated air_update funciton to use make json and make request functions
collinschwantes Sep 28, 2021
f367a52
added record id to request url for PATCH method
collinschwantes Sep 28, 2021
e6a3358
added record id and methods to air_make request, added methods to upd…
collinschwantes Sep 28, 2021
43c72a5
added methods for PATCH calls to make_json and make_request, added ty…
collinschwantes Sep 29, 2021
6416456
removed browser and print statements
collinschwantes Sep 29, 2021
c3548ad
added a delete method to the make request function and updated air_de…
collinschwantes Oct 5, 2021
a3efd0c
documented make_request and maKe_json functions
collinschwantes Oct 6, 2021
406522b
updated documentation and added a post method to make json
collinschwantes Oct 6, 2021
ecbb78c
properly place typecast arguments for POST and PATCH so that new valu…
collinschwantes Oct 6, 2021
7d93f0a
Merge pull request #3 from ecohealthalliance/fix/air_update
collinschwantes Oct 7, 2021
ca49108
Update readme.md
collinschwantes Oct 22, 2021
98f6d7e
added a download feature to air_get_attachments
collinschwantes Oct 22, 2021
e7911d5
fixed minor issues in documentation and function calls
collinschwantes Oct 22, 2021
740718f
changed the way file names are constructed to use the filename attrib…
collinschwantes Oct 29, 2021
8674702
Merge pull request #5 from ecohealthalliance/fix/download_file_name
collinschwantes Oct 29, 2021
30d9fa3
Update readme.rmd
collinschwantes Jun 24, 2022
41e8a05
added air_dump function
collinschwantes Jun 27, 2022
d360336
adding air_dump to package desc and namespace
collinschwantes Jun 27, 2022
e2d9f6b
using snake_case in stead of lower camel for consistency with package
collinschwantes Jun 27, 2022
f0c4e97
add recursive argument to create dir
collinschwantes Jun 27, 2022
68ce7f9
added documentation for set_diff
collinschwantes Jun 27, 2022
fce4fea
added note on where to find help for metadata tables
collinschwantes Jun 29, 2022
19b0452
added note on account requirements for metadata api
collinschwantes Jun 29, 2022
c24d409
breaking air_dump into component parts
collinschwantes Jun 30, 2022
513ae1a
added documentation for air_dump functions
collinschwantes Jun 30, 2022
cbcaf47
updated missing field warnings
collinschwantes Jun 30, 2022
27ce6db
Update issue templates
collinschwantes Jun 30, 2022
5fdc06b
Update issue templates
collinschwantes Jun 30, 2022
7377123
added data frame handling
collinschwantes Jun 30, 2022
54cc1fd
dropped browser from air_dump
collinschwantes Jun 30, 2022
64ffe86
csv writes to temp first and fixed example in flatten
collinschwantes Jun 30, 2022
9f5e3a2
udpated readme with instructions for editing renviron
collinschwantes Aug 11, 2022
5c0f3fd
functions to get data as raw json
collinschwantes Aug 19, 2022
8f3ab07
changed column order so that field is primary key
collinschwantes Aug 22, 2022
2fd2a54
added option to parse text in air_parse
collinschwantes Aug 23, 2022
45aa6ba
skip lines in excel reads
collinschwantes Aug 23, 2022
3ceef2f
updated docs so function reference is more specific
collinschwantes Aug 23, 2022
33e1cf8
Merge pull request #15 from ecohealthalliance/enhancement/attachments
collinschwantes Aug 23, 2022
8ac50b6
updated description file for our version of the package
collinschwantes Aug 23, 2022
a3d16ca
added filterByFormula paramter to air_get
collinschwantes Aug 24, 2022
0914a69
Merge pull request #17 from ecohealthalliance/enhancement/filter_by_f…
collinschwantes Aug 24, 2022
ba7d195
removed print statement from air_get
collinschwantes Sep 6, 2022
f6dde0a
Merge pull request #19 from ecohealthalliance/fix/drop_print_statements
collinschwantes Sep 6, 2022
a02513b
updated air_get_json function
collinschwantes Oct 18, 2022
30729ba
removed air_get_json ref from air_dump
collinschwantes Oct 18, 2022
218b51c
updated description
collinschwantes Oct 31, 2022
9b2dc62
Merge branch 'master' into feature/air_dump
collinschwantes Oct 31, 2022
0b2fd8d
Merge pull request #11 from ecohealthalliance/feature/air_dump
collinschwantes Oct 31, 2022
b6d7895
added json export functions
collinschwantes Oct 31, 2022
a13a58e
update version
collinschwantes Oct 31, 2022
0bef622
updated readme to reference tokens and not API keys
collinschwantes Dec 12, 2022
c3f50f6
updated readme
collinschwantes Dec 12, 2022
7dc16cc
updated example for clarity
collinschwantes Dec 12, 2022
beb2f85
removed reference to api key
collinschwantes Dec 12, 2022
81ab49d
added download function and helper functions for working with data th…
collinschwantes Dec 15, 2022
5d20a5f
Merge pull request #23 from ecohealthalliance/feature/air_dump
collinschwantes Dec 15, 2022
2998f9e
Update DESCRIPTION
collinschwantes Dec 15, 2022
177d99d
added options to get_metadata that add in record id fields and allow …
collinschwantes Dec 22, 2022
6582a1d
added snakecase option to airdump so names are consistent across meta…
collinschwantes Jan 20, 2023
16a1b1d
Merge pull request #31 from ecohealthalliance/feature/air_dump
collinschwantes Jan 20, 2023
fc41e85
updated readme to include warning about using metadata api
collinschwantes Jan 20, 2023
9ff797a
updated get schema and added placeholders for api metdata
collinschwantes Jan 23, 2023
32b64f0
added function to get metadata from api
collinschwantes Feb 10, 2023
653c205
added function to create metadata table
collinschwantes Feb 14, 2023
b02589e
added defaults for metadata fields_df
collinschwantes Feb 15, 2023
b422473
added descriptive metadata table
collinschwantes Mar 1, 2023
e0c9089
added a parse all sheets option to get_attachments
collinschwantes Mar 1, 2023
3dfce1a
Merge pull request #36 from ecohealthalliance/feature/parse_multiple_…
collinschwantes Mar 1, 2023
99d3894
Merge branch 'master' into feature/metadata_api
collinschwantes Mar 1, 2023
1757502
adding testing script and .env to git ignore
collinschwantes Mar 31, 2023
5f81a44
adding vignette and making templates more flexible
collinschwantes Apr 4, 2023
8a199b3
attachment fields may be empty so a warning is more appropriate
collinschwantes Apr 4, 2023
1b45239
added update description function and fixed a name issue
collinschwantes Apr 4, 2023
47b1cf7
make create_field capable of handling multiple fields
collinschwantes Apr 4, 2023
10270b6
added vignette for generating metadata and backups
collinschwantes Apr 4, 2023
7dd6b4f
added functions and example for bulk workspace download
collinschwantes Apr 5, 2023
e20d150
added bulk dump to csv and eval False
collinschwantes Apr 6, 2023
e33eb38
updated docs
collinschwantes Apr 6, 2023
bd88759
added example
collinschwantes Apr 6, 2023
745069a
updated namespace
collinschwantes Apr 6, 2023
4f23d7e
updated documentation
collinschwantes Apr 7, 2023
c67d1c6
updated the package namespace
collinschwantes Apr 7, 2023
aae3916
cleaned up documentation and ran package checks
collinschwantes Apr 7, 2023
a92b5fc
adding some things to help with vignette building
collinschwantes Apr 11, 2023
38da53d
updated version
collinschwantes Apr 11, 2023
30570cc
adding inst so that vignettes build
collinschwantes Apr 11, 2023
cefbd75
made structural and descriptive metadata behave similarly in air_dump
collinschwantes Apr 12, 2023
b0cee7c
Merge pull request #40 from ecohealthalliance/feature/metadata_api
collinschwantes Apr 12, 2023
11f5fb2
Update DESCRIPTION
collinschwantes Apr 12, 2023
8e39c61
adding a snake_case option
collinschwantes Apr 13, 2023
d39072d
updating docs
collinschwantes Apr 13, 2023
6e3924d
updating version
collinschwantes Apr 13, 2023
ad3a889
explicitly return df in metadata from api
collinschwantes Apr 13, 2023
c3597a1
updated version
collinschwantes Apr 13, 2023
defa30a
added snake_case rules for getting metadta from table
collinschwantes Apr 13, 2023
ca839ed
added status updates
collinschwantes Apr 13, 2023
9ee6d86
updated messages
collinschwantes Apr 13, 2023
ba5801e
added a polite option for downloads
collinschwantes Apr 13, 2023
3f28e9d
updated version
collinschwantes Apr 13, 2023
5482298
minor changes to default and print behavior
collinschwantes Apr 13, 2023
c7136f8
add check for attachments that already exist locally
collinschwantes Apr 13, 2023
68a79f6
added option to copy attachments into csv dump folder
collinschwantes Apr 14, 2023
01d08e7
Merge pull request #41 from ecohealthalliance/fix/metadata_routine
collinschwantes Apr 14, 2023
9afc0b8
wrapped download in map so url is length 1 character vector
collinschwantes Apr 14, 2023
4933005
added explicit check for character and lenght requirements
collinschwantes Apr 14, 2023
b2f2798
update_metadata table can now handle empty views
collinschwantes Apr 25, 2023
d807c7d
dropping filtering join for empty views
collinschwantes Apr 25, 2023
339cd0e
using schema for col check in case table is empty
collinschwantes Apr 25, 2023
981a435
updated md table check
collinschwantes Apr 25, 2023
ac5115b
fixed typo
collinschwantes Apr 25, 2023
0021137
Merge pull request #45 from ecohealthalliance/fix/empty-metadata-update
collinschwantes Apr 27, 2023
0aeeac2
added remotes section to description for deposits
collinschwantes May 23, 2023
0783561
Merge pull request #51 from ecohealthalliance/hotfix/set-remotes-dep
collinschwantes May 23, 2023
6625397
added manual id feature
collinschwantes Jun 12, 2023
540f443
Merge pull request #53 from ecohealthalliance/enhancement/manually_se…
collinschwantes Jun 12, 2023
69dd10a
updated dump to csv to allow for non-snake case outputs
collinschwantes Jun 14, 2023
a62f694
Merge pull request #55 from ecohealthalliance/fix/duplicate_fields
collinschwantes Jun 14, 2023
779dbbf
added option for dropping attachement names
collinschwantes Jun 29, 2023
696d508
updated version
collinschwantes Jun 29, 2023
991407c
Merge pull request #56 from ecohealthalliance/enhancement/att_id_option
collinschwantes Jun 29, 2023
c08fd28
updated air_get_attachements
collinschwantes Jul 18, 2023
6fb2360
Merge pull request #58 from ecohealthalliance/hotfix/drop-att-id
collinschwantes Jul 18, 2023
72ed9b8
added update field function
collinschwantes Jul 21, 2023
538f1ea
added documentation files
collinschwantes Jul 21, 2023
1e9a7ea
Merge pull request #60 from ecohealthalliance/feature/field_descriptions
collinschwantes Jul 31, 2023
051b778
updated documentation for air_get
collinschwantes Aug 2, 2023
a99b63f
Merge pull request #61 from ecohealthalliance/feature/field_descriptions
collinschwantes Aug 2, 2023
1409110
updating documentation
collinschwantes Aug 3, 2023
2367267
adding files for get_id functions
collinschwantes Aug 15, 2023
1b3a015
renamed a variable
collinschwantes Aug 17, 2023
532e9a2
adding preliminary post function
collinschwantes Aug 17, 2023
ac506f3
adding air_post and exposing get_id functions
collinschwantes Aug 17, 2023
96d535e
updated documentation
collinschwantes Aug 17, 2023
f031a55
Merge pull request #63 from ecohealthalliance/enhancement/air_get_post
collinschwantes Aug 17, 2023
468a1b1
dropped print statement from air_get
collinschwantes Aug 17, 2023
cff8f6c
properly formatted httr request
collinschwantes Aug 21, 2023
a4028cd
Merge pull request #65 from ecohealthalliance/hotfix/air_post
collinschwantes Aug 21, 2023
37f8b63
Update readme.md
rostal Apr 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
^IMG$
^readme_cache$
^\.travis\.yml$
^doc$
^Meta$
10 changes: 10 additions & 0 deletions .github/ISSUE_TEMPLATE/blank-issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: Blank Issue
about: Use this issue template for issues that are not bugs or enhancements
title: ''
labels: ''
assignees: ''

---


27 changes: 27 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Code to reproduce the behavior:

**Expected behavior**
A clear and concise description of what you expected to happen.


**Session info (please complete the following information):**

```
sessionInfo()
```

**Additional context**
Add any other context about the problem here.
17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''

---

**Describe why this feature should be added**
A clear and concise description of what the need is.

**Describe the behavior you expect**
A clear and concise description of what you want to happen.

**Additional context**
Add any other context or screenshots about the feature request here.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
.Rhistory
.RData
readme.html
testing_script.R
.env
/doc/
/Meta/
34 changes: 27 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
Package: airtabler
Type: Package
Title: Interface to the Airtable API
Version: 0.1.6
Date: 2017-09-17
Version: 0.2.16
Date: 2023-08-17
Author: Darko Bergant
Maintainer: Darko Bergant <darko.bergant@gmail.com>
Description: Provides access to the Airtable (airtable.com) API.
Maintainer: Collin Schwantes <schwantes@ecohealthalliance.org>
Description: Fork from Darko Bergant's package. Provides access to the Airtable (airtable.com) API.
Depends:
R (>= 3.2.0)
License: MIT + file LICENSE
URL: https://github.com/bergant/airtabler
URL: https://github.com/ecohealthalliance/airtabler
LazyData: TRUE
Encoding: UTF-8
Imports:
glue,
dplyr,
httr,
jsonlite
RoxygenNote: 6.0.1
jsonlite,
readxl,
curl,
purrr,
utils,
snakecase,
tidyselect,
rlang,
stringr,
tibble,
deposits,
assertthat
Remotes:
ropenscilabs/deposits
RoxygenNote: 7.2.3
Suggests:
knitr,
rmarkdown
VignetteBuilder: knitr
40 changes: 40 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,11 +1,51 @@
# Generated by roxygen2: do not edit by hand

S3method(print,airtable.base)
export(air_create_description_table)
export(air_create_field)
export(air_create_metadata_table)
export(air_create_table)
export(air_delete)
export(air_download_attachments)
export(air_dump)
export(air_dump_to_csv)
export(air_dump_to_json)
export(air_expand_csv_arrays)
export(air_fields_df_template)
export(air_fields_list_from_template)
export(air_generate_base_description)
export(air_generate_metadata_from_api)
export(air_generate_metadata_from_tables)
export(air_get)
export(air_get_attachments)
export(air_get_base_description_from_table)
export(air_get_base_id_from_url)
export(air_get_id_from_url)
export(air_get_json)
export(air_get_metadata_from_table)
export(air_get_record_id_from_url)
export(air_get_schema)
export(air_get_table_id_from_url)
export(air_get_view_id_from_url)
export(air_insert)
export(air_insert_data_frame)
export(air_list_bases)
export(air_make_json)
export(air_make_request)
export(air_post)
export(air_select)
export(air_table_template)
export(air_update)
export(air_update_data_frame)
export(air_update_description_table)
export(air_update_field)
export(air_update_metadata_table)
export(airtable)
export(fetch_all)
export(fetch_all_json)
export(flatten_col_to_chr)
export(get_offset)
export(get_unique_field_values)
export(multiple)
export(read_excel_url)
export(set_diff)
141 changes: 141 additions & 0 deletions R/air_download_attachments.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#' Download Airtable file attachments
#'
#' Download an attachment stored in air tables. Returns original dataframe
#' with an additional field called attachment_file_paths. The attachment_file_paths
#' field is of class list so it can handle multiple attachments per record. File
#' paths are prepended with record ids so that all file names are unique.
#'
#' @param x Data frame. Output from air_get or fetch_all.
#' @param field String. Name of field with file attachments in base
#' @param dir_name String. Where should files be downloaded to?
#' Will create the folder if it does not exist. Folders created are recursively.
#' @param ... reserved for additional arguments.
#' @param include_attachment_id Logical. Should you include the airtable attachment
#' ID to guarantee all file names are unique? Default is true.
#'
#' @return Returns x with an additional field called attachment_file_paths
#' @export air_download_attachments
#'
#' @examples
#' \dontrun{
#'
#' base <- "appXXXXXXXXX"
#' table_name <- "Table With Attachments"
#'
#' table_original <- air_get(base,table_name)
#'
#' table_with_file_paths <- air_download_attachments(x = table_with_attachments,
#' field = "attachment_field",
#' dir_name = "downloads")
#'
#' table_with_file_paths$attachment_file_paths
#'
#' }
#'
air_download_attachments <- function(x, field, dir_name = "downloads",include_attachment_id = TRUE,...){
#browser()

if(!is.data.frame(x)){
rlang::abort("x is not a dataframe")
}

if(!field %in% names(x)){
error_msg <- glue::glue("{field} not found in names(x). Check the name of the column
used to store attachments in airtable")

rlang::abort(error_msg)
}

if(!is.list(x[,field])){
error_msg <- glue::glue("{field} is not of class list. Verify the name of
the column used to store attachments in airtable")
rlang::warn(error_msg)

field_file_paths <- sprintf("%s_file_paths",field)

x$file_path <- NA

# using dynamic names in case a base has multiple file attachment
# columns
x <- dplyr::rename(x,{{field_file_paths}} := file_path)
return(x)
}

### subset to necessary records ----

# get files
xfield <- purrr::pluck(x,field)

### get files ----
dir.create(path = dir_name,recursive = TRUE)

xlist <- purrr::map(xfield, function(x){

if(is.null(x$url)){
ID <- x$id
warning(sprintf("Record ID %s is null",ID))
return(NULL)
}

# prepending attachment id in case the file naming convention
# of the user does not preclude duplicate file names for files
# with different contents - e.g. original file generation was
# structured like sample_1234/fasta.file sample_1235/fasta.file

filename_dest <- x$filename

if(include_attachment_id){
filename_dest <- sprintf("%s_%s", x$id,filename_dest)
} else {
message("include_attachement_id = FALSE. If file names are repeated,
only the first file with that name will be downloaded.")
}

dest <- sprintf("%s/%s", dir_name,filename_dest)

# sometimes the same file is attached multiple times
# if the file is already downloaded, don't add it again
# each attachment gets a unique id, so if the file changes,
# that id changes


if(all(file.exists(dest))){
not_downloaded_message <- glue::glue("\nFile already exists, not downloaded\n{dest}\n.")
print(not_downloaded_message)
return(dest)
}

# wrap in a map so that it works on linux systems where urls must explicitly
# be a length one character vector
purrr::map2(x$url, dest, function(url_item, dest_item){
if(is.character(url_item)& length(url_item )==1){
a <- utils::download.file(url = url_item,destfile = dest_item)
print(a)
} else {
print("url item not character or length greater than one")
print(url_item)
}
})


return(dest)
})

down_load_message <- glue::glue("Files downloaded here {dir_name}")

message(down_load_message)

field_file_paths <- sprintf("%s_file_paths",field)

x$file_path <- xlist

# using dynamic names in case a base has multiple file attachment
# columns
x <- dplyr::rename(x,{{field_file_paths}} := file_path)
return(x)

}




Loading