Hello,
I am running into an issue that I cannot understand.
I am reorganizing some json data from an API into a tibble I can work with.
I created 3 tibbles: income, income_titles, header
> head(income)
# A tibble: 6 x 4
..JSON document.id array.id Value
<chr> <int> <int> <chr>
1 "{\"Value\":\"Sales..." 1 1 Sales - 1% benefit from com clients
2 "{\"Value\":\"0.00\"..." 1 2 0.00
3 "{\"Value\":\"14.93..." 1 3 14.93
4 "{\"Value\":\"15.91..." 1 4 15.91
5 "{\"Value\":\"6.41\"..." 1 5 6.41
6 "{\"Value\":\"39.84..." 1 6 39.84
> head(header)
# A tibble: 6 x 3
..JSON array.id Month
<chr> <int> <chr>
1 "{\"Value\":\"30 Ju..." 2 30 Jun 21
2 "{\"Value\":\"30 Ma..." 3 30 May 21
3 "{\"Value\":\"30 Ap..." 4 30 Apr 21
4 "{\"Value\":\"30 Ma..." 5 30 Mar 21
5 "{\"Value\":\"28 Fe..." 6 28 Feb 21
6 "{\"Value\":\"30 Ja..." 7 30 Jan 21
> head(income_titles)
# A tibble: 6 x 3
..JSON document.id rowtitle
<chr> <int> <chr>
1 "{\"Value\":\"Sales..." 1 Sales - 1% benefit from com clients
2 "{\"Value\":\"Sales..." 2 Sales - Buying office
3 "{\"Value\":\"Sales..." 3 Sales - Commission from Suppliers
4 "{\"Value\":\"Sales..." 4 Sales - Incubation - Hosting & management
5 "{\"Value\":\"Sales..." 5 Sales - Incubation - Operation expenses
6 "{\"Value\":\"Sales..." 6 Sales - Incubation - Other projects
I want to join income_titles and header to income.
> head(income %>% left_join(header))
Joining, by = "array.id"
# A tibble: 6 x 4
document.id array.id Value Month
<int> <int> <chr> <chr>
1 1 1 Sales - 1% benefit from com clients NA
2 1 2 0.00 30 Jun 21
3 1 3 14.93 30 May 21
4 1 4 15.91 30 Apr 21
5 1 5 6.41 30 Mar 21
6 1 6 39.84 28 Feb 21
> head(income %>% left_join(income_titles))
Joining, by = "document.id"
# A tibble: 6 x 4
document.id array.id Value rowtitle
<int> <int> <chr> <chr>
1 1 1 Sales - 1% benefit from com clients Sales - 1% benefit from com clients
2 1 2 0.00 Sales - 1% benefit from com clients
3 1 3 14.93 Sales - 1% benefit from com clients
4 1 4 15.91 Sales - 1% benefit from com clients
5 1 5 6.41 Sales - 1% benefit from com clients
6 1 6 39.84 Sales - 1% benefit from com clients
But I can't join with both...
> income %>% left_join(income_titles) %>% left_join(header)
Joining, by = "document.id"
Joining, by = "array.id"
Error: Can't subset columns that don't exist.
x Location 3 doesn't exist.
ℹ There are only 2 columns.
Run `rlang::last_error()` to see where the error occurred.
> rlang::last_error()
<error/vctrs_error_subscript_oob>
Can't subset columns that don't exist.
x Location 3 doesn't exist.
ℹ There are only 2 columns.
Backtrace:
1. income %>% left_join(income_titles) %>% left_join(header)
3. dplyr:::left_join.data.frame(., header)
4. dplyr:::join_mutate(...)
7. tibble:::`[.tbl_df`(y_in, vars$y$out)
8. tibble:::vectbl_as_col_location(...)
11. vctrs::vec_as_location(j, n, names)
13. vctrs:::stop_subscript_oob(...)
14. vctrs:::stop_subscript(...)
Run `rlang::last_trace()` to see the full context.
> rlang::last_trace()
<error/vctrs_error_subscript_oob>
Can't subset columns that don't exist.
x Location 3 doesn't exist.
ℹ There are only 2 columns.
Backtrace:
█
1. ├─income %>% left_join(income_titles) %>% left_join(header)
2. ├─dplyr::left_join(., header)
3. └─dplyr:::left_join.data.frame(., header)
4. └─dplyr:::join_mutate(...)
5. ├─rlang::set_names(y_in[vars$y$out], names(vars$y$out))
6. ├─y_in[vars$y$out]
7. └─tibble:::`[.tbl_df`(y_in, vars$y$out)
8. └─tibble:::vectbl_as_col_location(...)
9. ├─tibble:::subclass_col_index_errors(...)
10. │ └─base::withCallingHandlers(...)
11. └─vctrs::vec_as_location(j, n, names)
12. └─(function () ...
13. └─vctrs:::stop_subscript_oob(...)
14. └─vctrs:::stop_subscript(...)
I am stuck and can't figure this one out. Any ideas?
catkfr