Skip to content

items_create ignores multiple parents #242

@aappling-usgs

Description

@aappling-usgs

I want the following code to create the following items under user_id():

* bigitem
  * item 1
  * item 2
* top-level item

Here's the code:

new_folder <- item_create(title='bigitem')
add_mult <- items_create(
	parent_id = c(new_folder$id, new_folder$id, user_id()),
	title = c("item 1", "item 2", "top-level item"))

What I get is three items nested under bigitem instead of bigitem and 'top-level item' being siblings:

* bigitem
  * item 1
  * item 2
  * top-level item

I think this is a bug, and I think it's due to a faulty else option in this line: https://github.com/USGS-R/sbtools/blob/master/R/items_create.R#L61. Rather than the current line,

item <- if (length(item) == 1) rep(item[[1]]$id, length(title)) else item[[1]]$id 

I suggest this:

item <- if (length(item) == 1) rep(item[[1]]$id, length(title)) else sapply(item, function(i) i$id) 

followed by some testing to make sure the change actually permits multiple parents for multiple items.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions