USGS-R / sbtools
Showing 1 of 7 files from the diff.
Other files ignored by Codecov
DESCRIPTION has changed.
NEWS.md has changed.
code.json has changed.
README.md has changed.

@@ -5,6 +5,8 @@
Loading
5 5
#' @template item_with_parent
6 6
#'
7 7
#' @param files A string vector of paths to files to be uploaded
8 +
#' @param scrape_files logical should the files be scraped for metadata? 
9 +
#' If TRUE, sciencebase will attempt to create extensions based on the files.
8 10
#' @export
9 11
#' @return An object of class \code{sbitem}
10 12
#' @examples \dontrun{
@@ -13,14 +15,21 @@
Loading
13 15
#' file <- system.file("examples", "books.json", package = "sbtools")
14 16
#' item_upload_create(user_id(), file)
15 17
#' }
16 -
item_upload_create = function(parent_id, files, ..., session=current_session()){
18 +
item_upload_create = function(parent_id, files, ..., scrape_files = TRUE, session=current_session()){
17 19
	
18 20
	if(length(files) > 50){
19 21
		warning('Trying to attach a large number of files to a SB item. SB imposes file limits which may cause this to fail')
20 22
	}
21 23
	
22 24
	item <- as.sbitem(parent_id)
23 -
	r = sbtools_POST(url = paste0(pkg.env$url_upload_create, item$id, '?title=title'), 
25 +
	
26 +
	params <- '?title=title'
27 +
	
28 +
	if(!scrape_files) {
29 +
		params <- paste0(params, '&scrapeFile=false')
30 +
	}
31 +
	
32 +
	r = sbtools_POST(url = paste0(pkg.env$url_upload_create, item$id, params), 
24 33
									 ...,
25 34
									 body = multi_file_body(files), 
26 35
									 session = session)
@@ -31,7 +40,9 @@
Loading
31 40
		stop('Not authenticated or lack of permission to parent object\nAunthenticate with the authenticate_sb function.')
32 41
	}
33 42
	
34 -
	return(as.sbitem(content(r)))
43 +
	item <- as.sbitem(content(r))
44 +
	
45 +
	return(check_upload(item, files))
35 46
}
36 47
37 48
#' 
@@ -39,7 +50,7 @@
Loading
39 50
#' @description Adds a file to an item
40 51
#'
41 52
#' @template manipulate_item
42 -
#' @param files A file path to upload.
53 +
#' @inheritParams item_upload_create
43 54
#'
44 55
#' @return An object of class \code{sbitem}
45 56
#'
@@ -52,19 +63,40 @@
Loading
52 63
#' item_append_files(res$id, "foobar.txt")
53 64
#' }
54 65
#' @export
55 -
item_append_files = function(sb_id, files, ..., session=current_session()){
66 +
item_append_files = function(sb_id, files, ..., scrape_files = TRUE, session=current_session()){
56 67
	
57 68
	if(length(files) > 50){
58 69
		warning('Trying to attach a large number of files to a SB item. SB imposes file limits which may cause this to fail')
59 70
	}
60 71
	
61 72
	item <- as.sbitem(sb_id)
62 -
	r = sbtools_POST(url = paste0(pkg.env$url_upload,'?id=', item$id), ...,
73 +
	
74 +
	params <- paste0("?id=", item$id)
75 +
	
76 +
	if(!scrape_files) {
77 +
		params <- paste0(params, "&scrapeFile=false")
78 +
	}
79 +
	
80 +
	r = sbtools_POST(url = paste0(pkg.env$url_upload, params), ...,
63 81
									 body = multi_file_body(files), 
64 82
									 session = session)
65 83
  
66 -
  return(as.sbitem(content(r)))
84 +
	item <- as.sbitem(content(r))
85 +
	
86 +
	return(check_upload(item, files))
87 +
	
88 +
}
89 +
90 +
check_upload <- function(item, files) {
91 +
	
92 +
	if(!all(basename(files) %in% sapply(item$files, function(x) x$name))) {
93 +
		warning("Not all files ended up in the item files. \n",
94 +
		"This indicates that a sciencebase extension was created with the file. \n",
95 +
		"set 'scrape_files' to FALSE to avoid this behavior. \n",
96 +
		"NOTE: 'scrape_files' will default to FALSE in a future version of sbtools.")
97 +
	}
67 98
	
99 +
	item
68 100
}
69 101
70 102
multi_file_body <- function(files){
Files Coverage
R 49.83%
Project Totals (51 files) 49.83%
Notifications are pending CI completion. Periodically Codecov will check the CI state, when complete notifications will be submitted. Push notifications now.

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading