grimbough / FITfileR

R package for reading data from FIT files using only native R code, rather than relying on external libraries.
https://msmith.de/FITfileR
50 stars 13 forks source link

Read error #28

Closed emily20wood closed 11 months ago

emily20wood commented 1 year ago

Hi there. Great package :) I am trying to read some cycling data from a fit file and getting the following error - any advice? I've attached the file. Cheers!

> file1_test <-FITfileR::readFitFile("data/team_pursuit_test.fit") Error in .readMessage_data(con = con, header = record_header, definition = definition) : Unable to read data message. Unknown field types detected.

I have recently updated R and R studio on a new machine - here is my session info.

R version 4.3.1 (2023-06-16) Platform: x86_64-apple-darwin20 (64-bit) Running under: macOS Ventura 13.4

Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Pacific/Auckland tzcode source: internal

attached base packages: team_pursuit_test.fit.zip

[1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached): [1] utf8_1.2.3 R6_2.5.1 tidyselect_1.2.0 magrittr_2.0.3 remotes_2.4.2.1 glue_1.6.2 tibble_3.2.1 pkgconfig_2.0.3
[9] FITfileR_0.1.6 dplyr_1.1.2 generics_0.1.3 lifecycle_1.0.3 cli_3.6.1 fansi_1.0.4 vctrs_0.6.3 compiler_4.3.1
[17] rprojroot_2.0.3 here_1.0.1 rstudioapi_0.15.0 tools_4.3.1 curl_5.0.2 pillar_1.9.0 rlang_1.1.1

grimbough commented 11 months ago

Thanks for the report. Sorry it took a while to get around to fixing. It should now work in version 0.1.7:

library(FITfileR)

## download and extract the example file
destfile = tempfile(fileext = ".zip")
url = "https://github.com/grimbough/FITfileR/files/12376057/team_pursuit_test.fit.zip"
dl = download.file(url = url, destfile = destfile)
example_file = unzip(destfile, exdir = tempdir())

## read and extract the records
fitFile <- readFitFile(example_file[1])
records <- records(fitFile) 

records
#> # A tibble: 273 × 9
#>    timestamp           power left_right_balance combined_pedal_smoothn…¹ cadence
#>    <dttm>              <int>              <int>                    <dbl>   <int>
#>  1 2023-08-03 08:41:30   976                 96                     56        71
#>  2 2023-08-03 08:41:31  1062                 51                     62.5      72
#>  3 2023-08-03 08:41:32  1196                 51                     63        76
#>  4 2023-08-03 08:41:33  1248                 53                     58        81
#>  5 2023-08-03 08:41:34  1241                 49                     54        88
#>  6 2023-08-03 08:41:35  1239                 50                     60        90
#>  7 2023-08-03 08:41:36  1157                 48                     54        92
#>  8 2023-08-03 08:41:37  1160                 51                     57        94
#>  9 2023-08-03 08:41:38  1101                 51                     58        98
#> 10 2023-08-03 08:41:39  1015                 46                     50        99
#> # ℹ 263 more rows
#> # ℹ abbreviated name: ¹​combined_pedal_smoothness
#> # ℹ 4 more variables: temperature <int>, heart_rate <int>, speed <dbl>,
#> #   distance <dbl>