DOI-USGS / DOI-USGS/sbtools

items_create ignores multiple parents

Open
#242 2 comments 0 reactions 1 assignee Claimed by @dblodgett-usgs View on GitHub
bug
Dominant language
R
Stars
24
Forks
20
PR merge metrics
No merged PRs in 30d

Description

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:
```r
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,
```r
item <- if (length(item) == 1) rep(item[[1]]$id, length(title)) else item[[1]]$id
```
I suggest this:
```r
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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.