Read error
mkln opened this issue · comments
Hi, cool package!
I'm getting an error when attempting to read a .fit file from a Hammerhead Karoo 2 device:
>library(FITfileR)
>test <- readFitFile("~/Downloads/testfile.fit")
Error in `filter()`:
! Problem while computing `..1 = key == tmp@fields[[manufacturer_id_idx]][1]`.
Caused by error in `tmp@fields[[manufacturer_id_idx]]`:
! attempt to select less than one element in get1index
Run `rlang::last_error()` to see where the error occurred.
Here's the file: testfile.fit.zip
Do you have the latest version of the package? Perhaps you could share the output of sessionInfo()
so I can see if there's any differences. Reading the the file works for me e.g.:
library(FITfileR)
## download and extract the example file
destfile = tempfile(fileext = ".zip")
url = "https://github.com/grimbough/FITfileR/files/10086014/testfile.fit.zip"
dl = download.file(url = url, destfile = destfile)
example_file = unzip(destfile, files = "testfile.fit", exdir = tempdir())
## read the file
fitFile <- readFitFile(example_file)
## display the device information
getMessagesByType(fitFile, message_type = "device_info")
#> $device_info_1
#> # A tibble: 2 × 9
#> timestamp device_index manufacturer produ…¹ sourc…² ant_d…³ product seria…⁴ devic…⁵
#> <dttm> <chr> <chr> <chr> <chr> <int> <int> <dbl> <int>
#> 1 2022-11-23 19:48:52 <NA> favero_electroni… 12 antplus 27489 12 1.80e9 11
#> 2 2022-11-23 19:48:52 <NA> fitcare 4 antplus 18623 4 0 120
#> # … with abbreviated variable names ¹product_name, ²source_type, ³ant_device_number,
#> # ⁴serial_number, ⁵device_type
#>
#> $device_info_2
#> # A tibble: 1 × 8
#> timestamp device_index manufacturer product_name product serial_number source_…¹ devic…²
#> <dttm> <chr> <chr> <chr> <int> <dbl> <chr> <int>
#> 1 2022-11-23 16:33:24 creator hammerhead Karoo 2 2 102500513 local 4
#> # … with abbreviated variable names ¹source_type, ²device_type
#>
#> $device_info_3
#> # A tibble: 19 × 11
#> timestamp device_index manufa…¹ produ…² product seria…³ sourc…⁴ devic…⁵ batte…⁶ batte…⁷
#> <dttm> <chr> <chr> <chr> <int> <dbl> <chr> <int> <chr> <dbl>
#> 1 2022-11-23 17:07:31 creator hammerh… Karoo 2 2 1.03e8 local 4 ok 3.99
#> 2 2022-11-23 17:21:11 creator hammerh… Karoo 2 2 1.03e8 local 4 ok 3.91
#> 3 2022-11-23 17:34:02 creator hammerh… Karoo 2 2 1.03e8 local 4 ok 3.94
#> 4 2022-11-23 17:41:16 creator hammerh… Karoo 2 2 1.03e8 local 4 ok 3.95
#> 5 2022-11-23 17:46:05 creator hammerh… Karoo 2 2 1.03e8 local 4 ok 3.93
#> 6 2022-11-23 18:05:21 creator hammerh… Karoo 2 2 1.03e8 local 4 ok 3.93
#> 7 2022-11-23 18:06:58 creator hammerh… Karoo 2 2 1.03e8 local 4 ok 3.91
#> 8 2022-11-23 18:19:49 creator hammerh… Karoo 2 2 1.03e8 local 4 ok 3.90
#> 9 2022-11-23 18:20:42 creator hammerh… Karoo 2 2 1.03e8 local 4 ok 3.90
#> 10 2022-11-23 18:25:26 creator hammerh… Karoo 2 2 1.03e8 local 4 ok 3.89
#> 11 2022-11-23 18:39:05 creator hammerh… Karoo 2 2 1.03e8 local 4 ok 3.85
#> 12 2022-11-23 18:43:06 creator hammerh… Karoo 2 2 1.03e8 local 4 ok 3.85
#> 13 2022-11-23 18:52:45 creator hammerh… Karoo 2 2 1.03e8 local 4 ok 3.84
#> 14 2022-11-23 19:02:23 creator hammerh… Karoo 2 2 1.03e8 local 4 ok 3.82
#> 15 2022-11-23 19:12:01 creator hammerh… Karoo 2 2 1.03e8 local 4 ok 3.84
#> 16 2022-11-23 19:20:03 creator hammerh… Karoo 2 2 1.03e8 local 4 ok 3.82
#> 17 2022-11-23 19:28:05 creator hammerh… Karoo 2 2 1.03e8 local 4 ok 3.80
#> 18 2022-11-23 19:36:07 creator hammerh… Karoo 2 2 1.03e8 local 4 ok 3.82
#> 19 2022-11-23 19:43:21 creator hammerh… Karoo 2 2 1.03e8 local 4 ok 3.81
#> # … with 1 more variable: charge <int>, and abbreviated variable names ¹manufacturer,
#> # ²product_name, ³serial_number, ⁴source_type, ⁵device_type, ⁶battery_status, ⁷battery_voltage
Here's my session info:
sessionInfo()
#> R version 4.2.2 (2022-10-31)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Linux Mint 20.3
#>
#> Matrix products: default
#> BLAS: /home/msmith/Applications/R/R-4.2.2/lib/libRblas.so
#> LAPACK: /home/msmith/Applications/R/R-4.2.2/lib/libRlapack.so
#>
#> locale:
#> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8
#> [4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=de_DE.UTF-8 LC_MESSAGES=en_US.UTF-8
#> [7] LC_PAPER=de_DE.UTF-8 LC_NAME=C LC_ADDRESS=C
#> [10] LC_TELEPHONE=C LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] FITfileR_0.1.5
#>
#> loaded via a namespace (and not attached):
#> [1] rstudioapi_0.14 knitr_1.41 magrittr_2.0.3 tidyselect_1.2.0 R6_2.5.1
#> [6] rlang_1.0.6 fastmap_1.1.0 fansi_1.0.3 stringr_1.4.1 highr_0.9
#> [11] dplyr_1.0.10 tools_4.2.2 xfun_0.35 utf8_1.2.2 DBI_1.1.3
#> [16] cli_3.4.1 withr_2.5.0 htmltools_0.5.3 assertthat_0.2.1 yaml_2.3.6
#> [21] digest_0.6.30 tibble_3.1.8 lifecycle_1.0.3 vctrs_0.5.1 fs_1.5.2
#> [26] glue_1.6.2 evaluate_0.18 rmarkdown_2.18 reprex_2.0.2 stringi_1.7.8
#> [31] compiler_4.2.2 pillar_1.8.1 generics_0.1.3 pkgconfig_2.0.3
I installed via devtools::install_github
, I think that's version 0.1.6.
Here's sessionInfo()
for two machines both of which give me the same error
> sessionInfo()
R version 4.2.2 (2022-10-31)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.0.1
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.2.2 tools_4.2.2
> sessionInfo()
R version 4.2.2 Patched (2022-11-10 r83330)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.5 LTS
Matrix products: default
BLAS/LAPACK: /opt/intel/compilers_and_libraries_2019.5.281/linux/mkl/lib/intel64_lin/libmkl_rt.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] dplyr_1.0.10 FITfileR_0.1.6
loaded via a namespace (and not attached):
[1] fansi_1.0.3 assertthat_0.2.1 utf8_1.2.2 R6_2.5.1 DBI_1.1.3 lifecycle_1.0.3
[7] magrittr_2.0.3 pillar_1.8.1 rlang_1.0.6 cli_3.4.1 rstudioapi_0.14 vctrs_0.5.1
[13] generics_0.1.3 tools_4.2.2 glue_1.6.2 compiler_4.2.2 pkgconfig_2.0.3 tidyselect_1.2.0
[19] tibble_3.1.8
Thanks. Looks like I'm the one running an old version of FITfileR 🤦♂️I guess I've got the latest version under R-devel but not R-4.2 I'll take a look at the issue later.
For now you could install version 0.1.5, but you'll probably have to pick through the git log to find the right commit to install from.
Ok, I'm currently on May 25 (https://github.com/grimbough/FITfileR/tree/a3b70fedb60de8555a7eb94cd99f13d257b2e242) which seems to be the last one that works without error. On the July 1 commit I get this:
> FITfileR::readFitFile("~/Downloads/testfile.fit")
Error in tmp@fields[[2]] : subscript out of bounds
Hope this helps!
Thanks for digging through the history. I made an assumption in my changes to address #20 that any developer messages would have a 'manufacturer' field. however that isn't the case in your files. Hopefully it's been fixed in the latest set of updates.