Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom CSV fails with header #1237

Open
2 tasks done
muschellij2 opened this issue Nov 28, 2024 · 1 comment · May be fixed by #1238
Open
2 tasks done

Custom CSV fails with header #1237

muschellij2 opened this issue Nov 28, 2024 · 1 comment · May be fixed by #1238

Comments

@muschellij2
Copy link
Contributor

if (header != "no header") {

Describe the bug
CSV with time/x/y/z fails when specifying rmc arguments. Following https://cran.r-project.org/web/packages/GGIR/vignettes/readmyacccsv.html still returns an error due to header.

62161_sub.csv.zip

To Reproduce

library(curl)
#> Warning: package 'curl' was built under R version 4.4.1
#> Using libcurl 8.4.0 with LibreSSL/3.3.6
library(GGIR)
zipfile = tempfile(fileext = ".zip")
curl_download(url = "https://github.com/user-attachments/files/17941173/62161_sub.csv.zip", destfile = zipfile)
exdir = tempfile()
unzip(zipfile, exdir = exdir)

datadir = file.path(exdir, "62161_sub.csv")
cat(readLines(datadir, n = 5), sep = "\n")
#> time,x,y,z
#> 2000-01-08T12:30:00.000Z,0.534,0.106,-0.877
#> 2000-01-08T12:30:00.013Z,0.487,0.126,-0.874
#> 2000-01-08T12:30:00.024Z,0.519,0.085,-0.874
#> 2000-01-08T12:30:00.036Z,0.543,0.114,-0.871

I = g.inspectfile(
  datadir,
  desiredtz = "UTC",
  configtz = "UTC",
  params_rawdata = list(
    #=====================
    rmc.dec = ".",
    rmc.firstrow.acc = 2,
    rmc.firstrow.header = 1,
    rmc.header.length = NULL,
    rmc.col.acc = 2:4,
    rmc.col.temp = NULL,
    rmc.col.time = 1,
    rmc.unit.acc = "g",
    rmc.unit.temp = "C",
    rmc.unit.time = "character",
    rmc.format.time = "%Y-%m-%d %H:%M:%OS",
    rmc.bitrate = NULL,
    rmc.dynamic_range = 6,
    rmc.unsignedbit = TRUE,
    rmc.origin = "1970-01-01",
    rmc.sf = 80L,
    rmc.headername.sf = NULL,
    rmc.headername.sn = NULL,
    rmc.headername.recordingid = NULL,
    rmc.header.structure = NULL,
    rmc.check4timegaps = FALSE,
    rmc.noise = 13,
    rmc.col.wear = NULL,
    rmc.doresample = FALSE,
    rmc.scalefactor.acc = 1
  )
)
I
#> $header
#>               
#> time         x
#> sample_rate 80
#> 
#> $monc
#> [1] 0
#> 
#> $monn
#> [1] "unknown"
#> 
#> $dformc
#> [1] 5
#> 
#> $dformn
#> [1] "csv"
#> 
#> $sf
#> [1] 80
#> 
#> $decn
#> [1] "."
#> 
#> $filename
#> [1] "62161_sub.csv"

outputdir = tempfile()
dir.create(outputdir)
GGIR::GGIR(
  datadir = datadir,
  outputdir = outputdir,
  studyname = "pax_g",
  print.filename = TRUE,
  desiredtz = "UTC",
  configtz = "UTC",
  sensor.location = "wrist", 
  verbose = TRUE,
  minimumFileSizeMB = 0, # don't let small gz files be skipped
  do.parallel = FALSE,
  dynrange = 6L, # dynamic range of 6g (https://wwwn.cdc.gov/Nchs/Nhanes/2011-2012/PAX80_G.htm)
  idloc = 6, # filename gives the ID before the "."
  
  #=====================
  # read.myacc.csv arguments for reading in CSVS
  #=====================
  #=====================
  rmc.dec = ".",
  rmc.firstrow.acc = 2,
  rmc.firstrow.header = 1,
  rmc.header.length = 1,
  rmc.col.acc = 2:4,
  rmc.col.temp = NULL,
  rmc.col.time = 1,
  rmc.unit.acc = "g",
  rmc.unit.temp = "C",
  rmc.unit.time = "character",
  rmc.format.time = "%Y-%m-%d %H:%M:%OS",
  rmc.bitrate = NULL,
  rmc.dynamic_range = 6,
  rmc.unsignedbit = TRUE,
  rmc.origin = "1970-01-01",
  rmc.sf = 80L,
  rmc.headername.sf = NULL,
  rmc.headername.sn = NULL,
  rmc.headername.recordingid = NULL,
  rmc.header.structure = NULL,
  rmc.check4timegaps = FALSE,
  rmc.noise = 13,
  rmc.col.wear = NULL,
  rmc.doresample = FALSE,
  rmc.scalefactor.acc = 1
)
#> 
#> Checking that user has write access permission for directory specified by argument outputdir: Yes
#> 
#>    GGIR version: 3.1.7
#> 
#>    Do not forget to cite GGIR in your publications via a version number and
#>    Migueles et al. 2019 JMPB. doi: 10.1123/jmpb.2018-0063. 
#>    See also: https://cran.r-project.org/package=GGIR/vignettes/GGIR.html#citing-ggir
#> 
#>    To make your research reproducible and interpretable always report:
#>      (1) Accelerometer brand and product name
#>      (2) How you configured the accelerometer
#>      (3) Study protocol and wear instructions given to the participants
#>      (4) GGIR version
#>      (5) How GGIR was used: Share the config.csv file or your R script.
#>      (6) How you post-processed / cleaned GGIR output
#>      (7) How reported outcomes relate to the specific variable names in GGIR
#> ________________________________________________________________________________
#>  Part 1 
#> 
#> Checking that user has read access permission for all files in data directory: Yes
#> 1 
#> File name: 62161_sub.csv
#> P1 file 1
#> 
#> Investigate calibration of the sensors with function g.calibrate:
#> 
#> Loading chunk: 1 2 3
#> Extract signal features (metrics) with the g.getmeta function:
#> 
#> Loading chunk: 1 2
#> Save .RData-file with: calibration report, file inspection report and all signal features...
#> 
#> ________________________________________________________________________________
#>  Part 2 
#> 1 
#> ________________________________________________________________________________
#>  Part 3 
#> 1
#> 
#> ________________________________________________________________________________
#>  Part 4 
#>  1
#> 
#> ________________________________________________________________________________
#>  Part 5 
#> 1 
#> ________________________________________________________________________________
#>  Report part 2 
#>  1
#> Error in if (header != "no header") {: argument is of length zero

Created on 2024-11-27 with reprex v2.1.1

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.4.0 (2024-04-24)
#>  os       macOS Sonoma 14.4.1
#>  system   x86_64, darwin20
#>  ui       X11
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       America/New_York
#>  date     2024-11-27
#>  pandoc   3.2 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/x86_64/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date (UTC) lib source
#>  cli           3.6.3   2024-06-21 [1] CRAN (R 4.4.0)
#>  curl        * 5.2.3   2024-09-20 [1] CRAN (R 4.4.1)
#>  data.table    1.16.2  2024-10-10 [1] CRAN (R 4.4.1)
#>  digest        0.6.37  2024-08-19 [1] CRAN (R 4.4.1)
#>  evaluate      1.0.1   2024-10-10 [1] CRAN (R 4.4.1)
#>  fastmap       1.2.0   2024-05-15 [1] CRAN (R 4.4.0)
#>  fs            1.6.5   2024-10-30 [1] CRAN (R 4.4.1)
#>  GGIR        * 3.1-7   2024-11-28 [1] Github (wadpac/GGIR@bb399f0)
#>  glue          1.8.0   2024-09-30 [1] CRAN (R 4.4.1)
#>  htmltools     0.5.8.1 2024-04-04 [1] CRAN (R 4.4.0)
#>  knitr         1.49    2024-11-08 [1] CRAN (R 4.4.1)
#>  lattice       0.22-6  2024-03-20 [1] CRAN (R 4.4.0)
#>  lifecycle     1.0.4   2023-11-07 [1] CRAN (R 4.4.0)
#>  reprex        2.1.1   2024-07-06 [1] CRAN (R 4.4.0)
#>  rlang         1.1.4   2024-06-04 [1] CRAN (R 4.4.0)
#>  rmarkdown     2.29    2024-11-04 [1] CRAN (R 4.4.1)
#>  rstudioapi    0.17.1  2024-10-22 [1] CRAN (R 4.4.1)
#>  sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.4.0)
#>  withr         3.0.2   2024-10-28 [1] CRAN (R 4.4.1)
#>  xfun          0.49    2024-10-31 [1] CRAN (R 4.4.1)
#>  yaml          2.3.10  2024-07-26 [1] CRAN (R 4.4.0)
#>  zoo           1.8-12  2023-04-13 [1] CRAN (R 4.4.0)
#> 
#>  [1] /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Info

  1. Sensor brand: ActiGraph
  2. Data format: 'CSV from NHANES
  3. Approximate recording duration: 17 hours
  4. Are you using a sleep diary to guide the sleep detection: NO

Desktop (please complete the following information):

  • OS: Mac OSX
  • GGIR Version: 3.1.7

Additional context
Add any other context about the problem here.

Before submitting

  • Have you tried the steps to reproduce? Do they include all relevant data and configuration? Does the issue you report still appear there?
  • Have you tried this on the latest master branch from GitHub?
@muschellij2 muschellij2 linked a pull request Nov 28, 2024 that will close this issue
3 tasks
@vincentvanhees
Copy link
Member

vincentvanhees commented Nov 28, 2024

I think this is a misunderstanding. By 'header' we mean file header, not column headers. With the following parameter set I am able to process your file:


# Test with read.myacc.csv on its own to first check that parameters are correct:
D = read.myacc.csv(rmc.file = "path/to/filefolder/file.csv",
                   rmc.nrow = 100, # only read start of file for this test
                   rmc.dec = ".",
                   rmc.firstrow.acc = 2,
                   rmc.firstrow.header = NULL, # <= changed!
                   rmc.header.length = NULL,
                   rmc.col.acc = 2:4,
                   rmc.col.temp = NULL,
                   rmc.col.time = 1,
                   rmc.unit.acc = "g",
                   rmc.unit.temp = "C",
                   rmc.unit.time = "character",
                   rmc.format.time = "%Y-%m-%dT%H:%M:%OS", # <= changed!
                   desiredtz = "", # <= needed when using this function on its own, in GGIR() calls this happens automatically
                   rmc.bitrate = NULL,
                   rmc.dynamic_range = 6,
                   rmc.unsignedbit = TRUE,
                   rmc.origin = "1970-01-01",
                   rmc.sf = 80L,
                   rmc.headername.sf = NULL,
                   rmc.headername.sn = NULL,
                   rmc.headername.recordingid = NULL,
                   rmc.header.structure = NULL,
                   rmc.check4timegaps = FALSE,
                   rmc.col.wear = NULL,
                   rmc.doresample = FALSE,
                   rmc.scalefactor.acc = 1)

> print(head(D$data))
       time     x     y      z
1 947334600 0.534 0.106 -0.877
2 947334600 0.487 0.126 -0.874
3 947334600 0.519 0.085 -0.874
4 947334600 0.543 0.114 -0.871
5 947334600 0.507 0.114 -0.868
6 947334600 0.481 0.120 -0.862

# Test with GGIR as a whole:
GGIR(datadir = "/path/to/filefolder",
     outputdir = "/some/other/path",
     rmc.dec = ".",
     rmc.firstrow.acc = 2,
     rmc.firstrow.header = NULL,
     rmc.header.length = NULL,
     rmc.col.acc = 2:4,
     rmc.col.temp = NULL,
     rmc.col.time = 1,
     rmc.unit.acc = "g",
     rmc.unit.temp = "C",
     rmc.unit.time = "character",
     rmc.format.time = "%Y-%m-%dT%H:%M:%OS",
     rmc.bitrate = NULL,
     rmc.dynamic_range = 6,
     rmc.unsignedbit = TRUE,
     rmc.origin = "1970-01-01",
     rmc.sf = 80L,
     rmc.headername.sf = NULL,
     rmc.headername.sn = NULL,
     rmc.headername.recordingid = NULL,
     rmc.header.structure = NULL,
     rmc.check4timegaps = FALSE,
     rmc.col.wear = NULL,
     rmc.doresample = FALSE,
     rmc.scalefactor.acc = 1)

The documentation mentions 'file header' a couple of time, but I understand that this should be emphasized more systematically across the whole page. So, action points from this is to update the vignette accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants