`get_activity_streams` Fails In `compile_activity` Due To `tidyr::spread` Error ("Object 'unlist.x.tosel..' Not Found")

by ADMIN 120 views

Introduction

When trying to fetch detailed streams for some recent activities using rStrava::get_activity_streams, the function fails. The error seems to originate from the internal compile_activity function while processing activity details. This issue affects multiple recent activities consistently.

Error Message & Backtrace

The specific error caught, along with the backtrace, is:

<error/purrr_error_indexed>
Error in `map()`:
ℹ In index: 10.
ℹ With name: workout_type.
Caused by error in `tidyr::spread()`:
Caused by error:
! 找不到对象'unlist.x.tosel..'
---
Backtrace:
     ▆
  1. ├─base::tryCatch(...)
  2. │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
  3. │   └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
  4. │     └─base (local) doTryCatch(return(expr), name, parentenv, handler)
  5. ├─rStrava::get_activity_streams(...)
  6. └─rStrava:::get_activity_streams.list(...)
  7.   └─rStrava::compile_activities(act_data, acts = acts, id = id)
  8.     └─purrr::map_dfr(actlist, compile_activity, columns = att)
  9.       └─purrr::map(.x, .f, ...)
 10.         └─purrr:::map_("list", .x, .f, ..., .progress = .progress)
 11.           ├─purrr:::with_indexed_errors(...)
 12.           │ └─base::withCallingHandlers(...)
 13.           ├─purrr:::call_with_cleanup(...)
 14.           └─rStrava (local) .f(.x[[i]], ...)
 15.             ├─tidyr::spread(temp, ColNames, unlist.x.tosel..)
 16.             └─tidyr:::spread.data.frame(temp, ColNames, unlist.x.tosel..)
 17.               └─tidyselect::vars_pull(names(data), !!enquo(value))
 18.                 ├─tidyselect:::with_chained_errors(...)
 19.                 │ └─base::withCallingHandlers(...)
 20.                 └─rlang::eval_tidy(expr, set_names(seq_along(vars), vars))

Steps to Reproduce / Example Code

The following code demonstrates the issue for a specific activity ID where the error occurs.

library(rStrava)

# --- Authentication ---
# Assuming 'stoken' is a valid, authenticated Token2.0 object obtained via:
# stoken <- rStrava::strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)
# (Client ID/Secret are not included here for security)
message("Assuming 'stoken' is a valid, authenticated Token2.0 object")

# --- Steps that cause the error ---
# Example activity ID that consistently fails:
failed_activity_id <- "13742582603" 

# Fetch the specific activity element the activity list
# (Assuming the activity is recent enough to be returned by get_activity_list)
message("Fetching activity list to find the element...")
activity_element <- NULL
all_activities <- tryCatch(rStrava::get_activity_list(stoken), error = function(e) NULL)
if (!is.null(all_activities)) {
   filtered_list <- Filter(function(act) as.character(act$id) == failed_activity_id, all_activities)
   if (length(filtered_list) > 0) {
       activity_element <- filtered_list[[1]]
       message("Activity element found.")
   } else {
       message("Activity element not found in list.")
   }
} else {
    message("Could not fetch activity list.")
}


# The failing call (if activity_element was found)
if (!is.null(activity_element)) {
    message("Trying to fetch streams...")
    streams_data <- tryCatch({
        # Note: The error seems to happen during compile_activities called within get_activity_streams
        rStrava::get_activity_streams(act_data = activity_element, 
                                      stoken = stoken, 
                                      types = c("time", "heartrate", "distance"), # Example types
                                      resolution = "medium", 
                                      series_type = "distance") 
    }, error = function(e) {
        print("Error occurred:")
        print(e)
        NULL 
    })
} else {
    message("Cannot attempt fetch, activity_element not found.")
}

Expected Behavior

The get_activity_streams function should successfully return a data frame containing the requested streams for the activity, or provide a more specific error message if the data is truly unavailable or invalid.

Actual Behavior

The function throws the error shown above. The backtrace indicates the error occurs within the internal function compile_activity (called via compile_activities), specifically when calling tidyr::spread. It seems an incorrect variable name (unlist.x.tosel..) is being passed as the value argument to spread, possibly when processing the workout_type attribute (index 10) of the activity details. This suggests a potential bug within rStrava.

Troubleshooting Done

I have tried using different combinations for the resolution parameter ("low", "medium", "high") and the series_type parameter ("distance", "time"), but the error persists for the affected activity ID (13742582603). This reinforces the idea that the issue lies within the package's internal processing logic rather than the specific API request parameters.

Environment

(Please run the following in your R console and paste the output here)

sessionInfo()
packageVersion("rStrava") 
packageVersion("httr")
packageVersion("tidyr") # Also relevant due to the error source
packageVersion("purrr") # Also relevant due to the error source
# Also mention your OS, e.g., Windows 10, macOS Sonoma, etc.

Conclusion

The get_activity_streams function fails in compile_activity due to a tidyr::spread error ("Object 'unlist.x.tosel..' not found"). This issue affects multiple recent activities consistently. The error seems to originate from the internal compile_activity function while processing activity details. The backtrace indicates the occurs within the internal function compile_activity (called via compile_activities), specifically when calling tidyr::spread. It seems an incorrect variable name (unlist.x.tosel..) is being passed as the value argument to spread, possibly when processing the workout_type attribute (index 10) of the activity details. This suggests a potential bug within rStrava.

Possible Solutions

  1. Check the rStrava package version: Ensure that the rStrava package is up-to-date. If not, update it to the latest version.
  2. Verify the tidyr package version: Ensure that the tidyr package is up-to-date. If not, update it to the latest version.
  3. Check for conflicts with other packages: Verify that there are no conflicts with other packages that might be causing the issue.
  4. Report the issue to the rStrava package maintainers: If none of the above solutions work, report the issue to the rStrava package maintainers, providing the necessary information and code to reproduce the issue.

Additional Information

If you have any additional information or code that might be relevant to this issue, please provide it. This will help the rStrava package maintainers to better understand and resolve the issue.

Q: What is the issue with the get_activity_streams function in rStrava?

A: The issue is that the function fails in the compile_activity function due to a tidyr::spread error ("Object 'unlist.x.tosel..' not found"). This error occurs when trying to fetch detailed streams for some recent activities using rStrava::get_activity_streams.

Q: What is the cause of the error?

A: The error seems to originate from the internal compile_activity function while processing activity details. The backtrace indicates that the error occurs within the internal function compile_activity (called via compile_activities), specifically when calling tidyr::spread. It seems an incorrect variable name (unlist.x.tosel..) is being passed as the value argument to spread, possibly when processing the workout_type attribute (index 10) of the activity details.

Q: What are the symptoms of the issue?

A: The symptoms of the issue are:

  • The get_activity_streams function fails to return the requested streams for the activity.
  • The function throws an error with the message "Object 'unlist.x.tosel..' not found".
  • The backtrace indicates that the error occurs within the internal function compile_activity (called via compile_activities), specifically when calling tidyr::spread.

Q: How can I troubleshoot the issue?

A: To troubleshoot the issue, you can try the following:

  • Check the rStrava package version: Ensure that the rStrava package is up-to-date. If not, update it to the latest version.
  • Verify the tidyr package version: Ensure that the tidyr package is up-to-date. If not, update it to the latest version.
  • Check for conflicts with other packages: Verify that there are no conflicts with other packages that might be causing the issue.
  • Report the issue to the rStrava package maintainers: If none of the above solutions work, report the issue to the rStrava package maintainers, providing the necessary information and code to reproduce the issue.

Q: What are the possible solutions to the issue?

A: The possible solutions to the issue are:

  • Update the rStrava package to the latest version.
  • Update the tidyr package to the latest version.
  • Check for conflicts with other packages and resolve them.
  • Report the issue to the rStrava package maintainers and provide the necessary information and code to reproduce the issue.

Q: How can I prevent the issue from occurring in the future?

A: To prevent the issue from occurring in the future, you can:

  • Regularly update the rStrava and tidyr packages to the latest versions.
  • Check for conflicts with other packages and resolve them.
  • Report any issues to the rStrava package maintainers and provide the necessary information and code to reproduce the issue.

Q: What are the system requirements for the rStrava package?

A: The system requirements for the rStrava package are:

  • R version 3.5 or later.
  • tidyr package version 1.0 or later.
  • rjson package version 0.2 or later.
  • httr package version .4 or later.

Q: How can I contact the rStrava package maintainers?

A: You can contact the rStrava package maintainers by:

  • Submitting an issue on the rStrava GitHub page.
  • Sending an email to the rStrava package maintainers.
  • Joining the rStrava package discussion group.

Q: What are the benefits of using the rStrava package?

A: The benefits of using the rStrava package are:

  • Easy access to Strava API data.
  • Simplified data manipulation and analysis.
  • Improved performance and efficiency.
  • Extensive documentation and support.

Q: How can I contribute to the rStrava package?

A: You can contribute to the rStrava package by:

  • Submitting issues and bug reports.
  • Providing feedback and suggestions.
  • Contributing code and documentation.
  • Participating in the rStrava package discussion group.