Error(s) in re-building vignettes:
--- re-building ‘introduction.Rmd’ using rmarkdown
Triact                 package:triact                  R Documentation

_R_6 _c_l_a_s_s _f_o_r _a_n_a_l_y_z_i_n_g _a_c_c_e_l_e_r_o_m_e_t_e_r _d_a_t_a _f_r_o_m _c_o_w_s

_D_e_s_c_r_i_p_t_i_o_n:

     An object for containing and analyzing data from accelerometers
     attached to a hind leg of cows. Analyses focus on the lying
     behaviour and on the cows' level of physical activity as detailed
     in Simmler & Brouwers (2024). For a usage example see
     'vignette("introduction", package = "triact")'.

_A_c_t_i_v_e _b_i_n_d_i_n_g_s:

     'data'
          Raw accelerometer data and analysis results. Mainly modified
          by $load_... and the $add_... methods

_M_e_t_h_o_d_s:

  _P_u_b_l_i_c _m_e_t_h_o_d_s:

         • 'Triact$new()'

         • 'Triact$load_files()'

         • 'Triact$load_table()'

         • 'Triact$check_orientation()'

         • 'Triact$add_lying()'

         • 'Triact$add_side()'

         • 'Triact$add_activity()'

         • 'Triact$summarize_intervals()'

         • 'Triact$summarize_bouts()'

         • 'Triact$extract_liedown()'

         • 'Triact$extract_standup()'

         • 'Triact$clone()'

  _M_e_t_h_o_d '_n_e_w()':

       Create a new Triact object.

    _U_s_a_g_e:

         Triact$new()
         

    _R_e_t_u_r_n_s:

         A new Triact object.


    _E_x_a_m_p_l_e_s:

         # create a Triact object
         my_triact <- Triact$new()
         

  _M_e_t_h_o_d '_l_o_a_d__f_i_l_e_s()':

       Import acceleration data of one or multiple cows from
       delimiter-separated text files into the Triact object. Importing
       from multiple files from the same cows is possible but data
       should follow each other without any gaps in time (overlap is
       allowed as duplicates after concatenation will be removed). The
       filenames must allow unique identification of the cow
       (parameter: 'id_substring'). Accelerometer sampling frequency
       must be consistent across the files. Acceleration should be in
       units of _g_ and represent _proper acceleration_. Triaxial,
       biaxial, and uniaxial accelerometer data are allowed, but only
       triaxial data corresponding to relative body directions allows
       full functionality.

       _Important_: Make sure to correctly specify how to map the axes
       as named by the accelerometer (e.g., x, y, z) to the body
       relative axes as used in triact (parameter:
       'timeFwdUpRight_cols'). For an example see
       'vignette("introduction", package = "triact")'.

    _U_s_a_g_e:

         Triact$load_files(
                 input,
                 id_substring,
                 timeFwdUpRight_cols,
                 time_format  = NULL,
                 tz           = Sys.timezone(),
                 skip         = "__auto__",
                 sep          = "auto",
                 header       = "auto",
                 dec          = ".",
                 start_time   = NULL,
                 end_time     = NULL,
                 parallel     = 1,
                                ...)
         

    _A_r_g_u_m_e_n_t_s:

         'input'
             Specifies the input acceleration data files. Character
             vector with the name(s) of the file(s) or a directory
             containing the files (files can be in subdirectories). If
             it does not contain absolute paths, the directory or file
             name(s) are relative to the current working directory,
             'getwd()'.

         'id_substring'
             Integer vector identifying the substring of the file names
             representing the unique identifier of the cows by
             character position: c(first, last), e.g, 'c(1, 5)' for
             first to fifth character. Alternatively, a Perl-like
             regular expression matching the substring.

         'timeFwdUpRight_cols'
             Integer vector specifying the columns containing the time,
             and the forward, up, and right axis acceleration data:
             c(time, fwd, up, right). Missing acceleration axes are
             specified as 'NA'. A negative mathematical sign is used to
             indicate that the recorded data reflects the opposite
             direction (e.g., if you recorded backward acceleration,
             specify the forward acceleration column with a negative
             mathematical sign).

         'time_format'
             Character vector specifying the date-time format
             corresponding to the acceleration files (syntax as in
             'strptime'). If 'NULL' a date-time format as tried by
             as.POSIX* is expected. _Default:_ 'NULL'

         'tz'
             Character vector specifying the time zone. _Default:_
             'Sys.timezone()'

         'skip'
             An integer indicating the number of lines to skip before
             starting the search for the first data line, which is the
             first row with a consistent number of columns.
             Alternatively, a (sub)string specifying the line at which
             to start the search, or '"__auto__"' to leave the decision
             to 'fread'. _Default:_ '"__auto__"'

         'sep'
             The separator between columns in the acceleration data
             files. If '"auto"', it is automatically detected by
             'fread' according to the character in the set [,\t |;:]
             that separates the sample of rows into the most number of
             lines with the same number of fields. _Default:_ '"auto"'

         'header'
             A logical value that indicates whether the first data line
             (afer considering 'skip') contains column names.
             Alternatively, '"auto"' to autmatically detect by 'fread'
             according to whether every non-empty field on the first
             data line is type character. _Default:_ '"auto"'

         'dec'
             The decimal separator as in 'fread'. _Default:_ '"."'

         'start_time'
             Time from which the data should be considered. Formatted
             as "%Y-%m-%d %H:%M:%OS" or in another format automatically
             tried by as.POSIX*. _Default:_ 'NULL'

         'end_time'
             Time up to which the data should be considered. Formatted
             as "%Y-%m-%d %H:%M:%OS" or in another format automatically
             tried by as.POSIX*. _Default:_ 'NULL'

         'parallel'
             An integer indicating the number of files that are read in
             parallel. For 'parallel > 1' the reading of the individual
             file is set to single-threaded to avoid nested
             parallelization. This behavior can be overwritten by
             additionally passing 'nThread' via '...'  argument, which
             is passed on to 'fread'. _Default:_ '1'

         '...'
             Further arguments passed to 'fread'.


    _R_e_t_u_r_n_s:

         Returns the Triact object itself, but modified by reference.


    _E_x_a_m_p_l_e_s:

         # create a Triact object
         my_triact <- Triact$new()
         
         input_dir <- system.file("extdata", package = "triact")
         
         my_triact$load_files(input = input_dir,
                              id_substring = c(1, 5),
                              timeFwdUpRight_cols = c(1, -2, 3, -4),
                              skip = "DATA")
         
         # inspect imported data
         head(my_triact$data)
         

  _M_e_t_h_o_d '_l_o_a_d__t_a_b_l_e()':

       Import acceleration data from a data.frame-like table (see
       'cows_5hz' as an example). The table should contain the
       following columns:

         _colname_  _type_   _description_                                 
         id         Factor   unique id for the cow                         
         time       POSIXct  timestamp                                     
         acc_fwd    numeric  acceleration from _forward_ axis (units: _g_) 
         acc_up     numeric  acceleration from _up_ axis (units: _g_)      
         acc_right  numeric  acceleration from _right_ axis (units: _g_)   
        
       The accelerometer sampling frequency must be the same across all
       cows (id). No time gaps are allowed (within data of one id). One
       or two of the acceleration columns may be missing, but the
       possible analyses are then limited.

       _Important_: Make sure the accelerometer axes correctly
       represent body relative axes as used in triact (forward, up,
       right). For an example see 'vignette("introduction", package =
       "triact")'.

    _U_s_a_g_e:

         Triact$load_table(table)
         

    _U_s_a_g_e (_a_l_t_e_r_n_a_t_i_v_e _s_y_n_t_a_x):

         Triact$data <- table
         

    _A_r_g_u_m_e_n_t_s:

         'table'
             Data frame-like table containing the data to import. Must
             follow the requirements detailed in the description above.


    _R_e_t_u_r_n_s:

         Returns the Triact object itself, but modified by reference.


    _E_x_a_m_p_l_e_s:

         # create a Triact object
         my_triact <- Triact$new()
         
         my_triact$load_table(cows_5hz)
         
         # inspect imported data
         head(my_triact$data)
         

  _M_e_t_h_o_d '_c_h_e_c_k__o_r_i_e_n_t_a_t_i_o_n()':

       Checks for each id (unique identifier of the cow) whether the
       accelerometer may have been unintentionally mounted 180° rotated
       in the sagittal plane to the hind leg. If identified as such,
       the mathematical correction is applied, i.e. the forward and up
       axes are negated (multiplied by -1), i.e. the axes are
       mathematically rotated in order to comply with the orientation
       as specified when loading in the data.  The check is 'sum(acc_up
       > crit) < sum(acc_up < (-1 * crit))' with 'crit = 0.5' by
       default.

    _U_s_a_g_e:

         Triact$check_orientation(crit = 0.5, interactive = TRUE)
         

    _A_r_g_u_m_e_n_t_s:

         'crit'
             Critical value used in the check according to the
             expression noted in the description above.  _Default:_
             '0.5'

         'interactive'
             A logical value that indicates whether the function should
             interactively prompt the user before applying the
             correction. _Default:_ 'TRUE'


    _R_e_t_u_r_n_s:

         Returns the Triact object itself, but modified by reference.


    _E_x_a_m_p_l_e_s:

         # create a Triact object
         my_triact <- Triact$new()
         
         my_triact$load_table(cows_5hz)
         
         my_triact$check_orientation()
         

  _M_e_t_h_o_d '_a_d_d__l_y_i_n_g()':

       Classify data into lying and standing and add results as column
       'lying' to the Triact object. Additionally, lying and standing
       bouts are uniquely numbered per id (cow) in column 'bout_nr'.
       The simple rule-based algorithm is composed of three steps: In
       the first step, the _up_ acceleration is filtered to obtain the
       gravity component of the signal. In the second step, a threshold
       is used to classify the (filtered) gravitational acceleration
       into lying and standing. Finally, in the third step, lying bouts
       shorter than a given minimum duration are reclassified as
       standing. The last step can be performed analogous for standing
       bouts, but is not recommended by default. See Simmler & Brouwers
       (2024) for a detailed discussion.

    _U_s_a_g_e:

         Triact$add_lying(
               filter_method = "median",
               crit_lie = 0.5,
               minimum_duration_lying = 30,
               minimum_duration_standing = NULL,
               add_filtered = FALSE,
               window_size = 10,
               cutoff = 0.1,
               order = 1)
         

    _A_r_g_u_m_e_n_t_s:

         'filter_method'
             Filter method to be applied to obtain the gravity
             component of the acceleration on the _up_ axis. Options
             are '"median"', for median filter, and '"butter"' for a
             bidirectional (zero-lag) Butterworth low-pass filter.
             _Default:_ '"median"'

         'crit_lie'
             Threshold for classifying the gravitational acceleration
             on _up_ axis into lying (below threshold) and standing
             (above threshold). _Default:_ '0.5'

         'minimum_duration_lying'
             Minimum duration for lying bouts in seconds. Lying bouts
             shorter than this threshold are considered false and
             reclassified as standing. _Default:_ '30'

         'minimum_duration_standing'
             Minimum duration for standing bouts in seconds. Standing
             bouts shorter than this threshold are considered false and
             reclassified as lying.  _Default:_ 'NULL'

         'add_filtered'
             Logical value that indicates whether the filtered gravity
             component of the _up_ acceleration should be added to the
             Triact object.  _Default:_ 'FALSE'

         'window_size'
             Window size in seconds for filter method 'median'.
             _Default:_ '10'

         'cutoff'
             Cutoff frequency for low-pass filtering in Hz for filter
             method 'butter'. _Default:_ '0.1'

         'order'
             Filter order for filter method 'butter'. _Default:_ '1'


    _R_e_t_u_r_n_s:

         Returns the Triact object itself, but modified by reference.


    _E_x_a_m_p_l_e_s:

         # create a Triact object
         my_triact <- Triact$new()
         
         my_triact$load_table(cows_5hz)
         
         my_triact$add_lying()
         
         # inspect result
         head(my_triact$data)
         

  _M_e_t_h_o_d '_a_d_d__s_i_d_e()':

       Classify lying bouts into left and right lying side and add the
       results as column 'side' to the Triact object. The simple
       one-step algorithm determines whether the majority of the
       _right_ acceleration values measured during that bout are above
       (left lying side) or below (right lying side) a threshold. The
       default threshold depends on which hind leg (left/right hind
       leg) the accelerometer is attached to, taking into account the
       asymmetry of the cow's natural lying position. See Simmler &
       Brouwers (2024) for a detailed explanation.

    _U_s_a_g_e:

         Triact$add_side(left_leg, crit_left = if (left_leg) 0.5 else -0.5)
         

    _A_r_g_u_m_e_n_t_s:

         'left_leg'
             Logical indicating whether the accelerometers were
             attached to the left hind leg ('TRUE') or to the right
             hind leg ('FALSE'). This information is used to choose the
             default value for 'crit_left'. It is ignored if
             'crit_left' is specified by the user.

         'crit_left'
             Threshold for classifying lying on left versus right side
             based on _right_ acceleration.  _Default:_ '0.5' if
             'left_leg' is 'TRUE', else '-0.5'


    _R_e_t_u_r_n_s:

         Returns the Triact object itself, but modified by reference.


    _E_x_a_m_p_l_e_s:

         # create a Triact object
         my_triact <- Triact$new()
         
         my_triact$load_table(cows_5hz)
         
         my_triact$add_lying()
         
         my_triact$add_side(left_leg = TRUE)
         
         # inspect result
         head(my_triact$data)
         

  _M_e_t_h_o_d '_a_d_d__a_c_t_i_v_i_t_y()':

       Calculate proxies for the physical activity level. By default,
       the L2 norm of the dynamic body acceleration (DBA) vector is
       calculated. The corresponding L1 norm is optionally available.
       Also, the L1 and L2 norms of the jerk vector can be calculated.
       By default, all activity values during lying bouts are
       'adjusted' to zero, i.e., periods when cows are lying are
       considered as 'inactive' by definition. See Simmler & Brouwers
       (2024) for details.

    _U_s_a_g_e:

         Triact$add_activity(
                 dynamic_measure = "dba",
                 norm = "L2",
                 adjust = TRUE,
                 filter_method = "median",
                 keep_dynamic_measure = FALSE,
                 window_size = 10,
                 cutoff = 0.1,
                 order = 1)
         

    _A_r_g_u_m_e_n_t_s:

         'dynamic_measure'
             Type of dynamic measure to base the activity proxy on.
             Options are '"dba"', for dynamic body acceleration, and
             '"jerk"', for the jerk vector. One or both can be
             provided, e.g., '"dba"' or 'c("dba", "jerk")'. _Default:_
             '"dba"'

         'norm'
             The type of norm to be calculated. Options are '"L1"' and
             '"L2"'. One or both can be provided, e.g., '"L1"' or
             'c("L1", "L2")'. _Default:_ '"L2"'

         'adjust'
             A logical value that indicates whether the proxies for
             physical activity should be 'adjusted' to 0 during lying
             bouts, i.e., whether cows should be considered as inactive
             by definition when lying. _Default:_ 'TRUE'

         'filter_method'
             Filter method to be used to determine the gravity
             component subtracted from the raw acceleration to obtain
             the dynamic body acceleration. Options are '"median"', for
             median filter, and '"butter"' for a bidirectional
             (zero-lag) Butterworth low-pass filter. _Default:_
             '"median"'

         'keep_dynamic_measure'
             A logical value that indicates whether the intermediate
             data, being the dynamic body acceleration vector and/or
             the jerk vector, should be added to the Triact object.
             _Default:_ 'FALSE'

         'window_size'
             Window size in seconds for filter method 'median' used in
             DBA-based proxies.  _Default:_ '10'

         'cutoff'
             Cutoff frequency for low-pass filtering in Hz for filter
             method 'butter' used in DBA-based proxies. _Default:_
             '0.1'

         'order'
             Filter order for filter method 'butter' used in DBA-based
             proxies. _Default:_ '1'


    _R_e_t_u_r_n_s:

         Returns the Triact object itself, but modified by reference.


    _E_x_a_m_p_l_e_s:

         # create a Triact object
         my_triact <- Triact$new()
         
         my_triact$load_table(cows_5hz)
         
         my_triact$add_lying()
         
         my_triact$add_activity()
         
         # inspect result
         head(my_triact$data)
         

  _M_e_t_h_o_d '_s_u_m_m_a_r_i_z_e__i_n_t_e_r_v_a_l_s()':

       Summarizes the data in the Triact object, activity and lying
       behaviour, by regular intervals. The information contained in
       the output table depends on the analyses you added to the Triact
       object using the $add_activity(), $add_lying(), and $add_side()
       methods. With 'bout = TRUE' information on bouts per interval
       (number and mean bout duration) will be returned additionally.
       With 'side = TRUE' summarized information such lying duration is
       additionally provided separately for the lying side
       (left/right). For measures such as the number of lying bouts or
       mean lying bout duration, a weighted mean ('wMean...') is
       calculated with the weights being the proportion of the
       individual bout overlapping with the respective interval. See
       interval_summary for a complete list of summarized measures and
       Simmler & Brouwers (2024) for details.

    _U_s_a_g_e:

         Triact$summarize_intervals(
               interval = "hour",
               lag_in_s = 0,
               duration_units = "mins",
               bouts = FALSE,
               side = FALSE,
               calc_for_incomplete = FALSE)
         

    _A_r_g_u_m_e_n_t_s:

         'interval'
             Character string specifying the intervals to be analyzed.
             Any unique English abbreviation valid for the 'unit'
             argument of 'floor_date' is allowed, e.g., '"hour"',
             '"min"', '"10 mins"', and '"0.5 hours"'. _Default:_
             '"hour"'

         'lag_in_s'
             Lag in seconds with respect to the full hour or full day.
             Determines the start of the intervals. _Default:_ '0'

         'duration_units'
             Unit in which durations should be returned. Options are
             '"secs"', '"mins"' and '"hours"'. _Default:_ '"mins"'

         'bouts'
             Logical indicating whether information on bouts should be
             additionally summarized. _Default:_ 'FALSE'

         'side'
             Logical indicating whether lying side should be considered
             in the summary. _Default:_ 'FALSE'

         'calc_for_incomplete'
             Logical indicating whether a complete summary should also
             be returned for the incompletely observed intervals (first
             and last interval for each cow) and for any parameter
             using information of incompletely observed bouts (first
             and last bout for each cow). Please note that these are
             ill-defined. _Default:_ 'FALSE'


    _R_e_t_u_r_n_s:

         A table with summaries by interval (rows). See
         interval_summary for a complete list.


    _E_x_a_m_p_l_e_s:

         # create a Triact object
         my_triact <- Triact$new()
         
         my_triact$load_table(cows_5hz)
         
         my_triact$add_lying()
         
         int_summary <- my_triact$summarize_intervals()
         
         # inspect result
         head(int_summary)
         

  _M_e_t_h_o_d '_s_u_m_m_a_r_i_z_e__b_o_u_t_s()':

       Summarizes the data in the Triact object, activity and lying
       behaviour, by lying/standing bouts. The information contained in
       the output table depends on the analyses you added to the Triact
       object using the $add_activity(), $add_lying(), and $add_side()
       methods. See bout_summary for a complete list of summarized
       measures and Simmler & Brouwers (2024) for details.

    _U_s_a_g_e:

         Triact$summarize_bouts(
               bout_type = "both",
               duration_units = "mins",
               calc_for_incomplete = FALSE)
         

    _A_r_g_u_m_e_n_t_s:

         'bout_type'
             Type of bout to be considered. Options are '"both"',
             '"lying"', and '"standing"'. _Default:_ '"both"'

         'duration_units'
             Units in which durations should be returned. Options are
             '"secs"', '"mins"', and '"hours"'. _Default:_ '"mins"'

         'calc_for_incomplete'
             Logical indicating whether a complete summary should also
             be returned for the incompletely observed bouts (first and
             last bout for each cow). Please note that these are
             ill-defined. _Default:_ 'FALSE'


    _R_e_t_u_r_n_s:

         A table with summaries by bout (rows).  See bout_summary for a
         complete list.


    _E_x_a_m_p_l_e_s:

         # create a Triact object
         my_triact <- Triact$new()
         
         my_triact$load_table(cows_5hz)
         
         my_triact$add_lying()
         
         bouts_summary <- my_triact$summarize_bouts()
         
         # inspect result
         head(bouts_summary)
         

  _M_e_t_h_o_d '_e_x_t_r_a_c_t__l_i_e_d_o_w_n()':

       Extracts data associated with liedown events (standing-to-lying
       transitions). Operates in two modes, see _Returns_ section.

    _U_s_a_g_e:

         Triact$extract_liedown(sec_before = 0, sec_after = 0)
         

    _A_r_g_u_m_e_n_t_s:

         'sec_before'
             From how many seconds before the liedown events data
             should be considered. _Default:_ '0'

         'sec_after'
             Up to how many seconds after the liedown events data
             should be considered. _Default:_ '0'


    _R_e_t_u_r_n_s:

         With default settings, a table with one entry per liedown
         event, with timestamp and bout_nr of the lying bout, plus
         lying side information (if available). With parameters
         'sec_before' and/or 'sec_after' > 0, a list containing
         individual tables per liedown event. These tables are extracts
         of all data in the Triact object from within the defined time
         window around the liedown events.


    _E_x_a_m_p_l_e_s:

         # create a Triact object
         my_triact <- Triact$new()
         
         my_triact$load_table(cows_5hz)
         
         my_triact$add_lying()
         
         l_downs <- my_triact$extract_liedown()
         
         # inspect result
         print(l_downs)
         

  _M_e_t_h_o_d '_e_x_t_r_a_c_t__s_t_a_n_d_u_p()':

       Extracts data associated with standup events (lying-to-standing
       transitions). Operates in two modes, see _Returns_ section.

    _U_s_a_g_e:

         Triact$extract_standup(sec_before = 0, sec_after = 0)
         

    _A_r_g_u_m_e_n_t_s:

         'sec_before'
             From how many seconds before the standup events data
             should be considered. _Default:_ '0'

         'sec_after'
             Up to how many seconds after the standup events data
             should be considered. _Default:_ '0'


    _R_e_t_u_r_n_s:

         With default settings, a table with one entry per standup
         event, with timestamp and bout_nr of the lying bout, plus
         lying side information (if available). With parameters
         'sec_before' and/or 'sec_after' > 0, a list containing
         individual tables per standup event. These tables are extracts
         of all data in the Triact object from within the defined time
         window around the standup events.


    _E_x_a_m_p_l_e_s:

         # create a Triact object
         my_triact <- Triact$new()
         
         my_triact$load_table(cows_5hz)
         
         my_triact$add_lying()
         
         st_ups <- my_triact$extract_standup()
         
         # inspect result
         print(st_ups)
         

  _M_e_t_h_o_d '_c_l_o_n_e()':

       Copy a Triact object. By default a shallow copy is returned,
       which does not completely copy the data contained in the Triact
       object. For a complete copy use 'deep = TRUE'.

    _U_s_a_g_e:

         Triact$clone(deep = FALSE)
         

    _A_r_g_u_m_e_n_t_s:

         'deep'
             Whether to make a deep copy. _Default:_ 'FALSE'


    _R_e_t_u_r_n_s:

         A copy of the Triact object.


    _E_x_a_m_p_l_e_s:

         # create a Triact object
         my_triact <- Triact$new()
         
         my_triact$load_table(cows_5hz)
         
         # create a complete copy
         my_triact_cp = my_triact$clone(deep = TRUE)
         

_R_e_f_e_r_e_n_c_e_s:

     Simmler. M., Brouwers S. P., 2024. _triact_ package for R:
     Analyzing the lying behavior of cows from accelerometer data.
     PeerJ, 12:e17036. doi:10.7717/peerj.17036
     <https://doi.org/10.7717/peerj.17036>

_E_x_a_m_p_l_e_s:

     ## Please read the "introduction" vignette for more detailed examples
     
     ## -------------------------
     # method '$new'
     ## -------------------------
     
     # create a Triact object
     my_triact <- Triact$new()
     
     ## -------------------------
     # method '$load_files'
     ## -------------------------
     
     
     # create a Triact object
     my_triact <- Triact$new()
     
     input_dir <- system.file("extdata", package = "triact")
     
     my_triact$load_files(input = input_dir,
                          id_substring = c(1, 5),
                          timeFwdUpRight_cols = c(1, -2 ,3, -4),
                          skip = "DATA")
     
     # inspect imported data
     head(my_triact$data)
     
     
     ## -------------------------
     # method 'load_table'
     ## -------------------------
     
     # create a Triact object
     my_triact <- Triact$new()
     
     my_triact$load_table(cows_5hz)
     
     # inspect imported data
     head(my_triact$data)
     
     ## -------------------------
     # method 'check_orientation'
     ## -------------------------
     
     my_triact$check_orientation()
     
     ## -------------------------
     # method 'add_lying'
     ## -------------------------
     
     my_triact$add_lying()
     
     # inspect result
     head(my_triact$data)
     
     ## -------------------------
     # method 'add_side'
     ## -------------------------
     
     my_triact$add_side(left_leg = TRUE)
     
     # inspect result
     head(my_triact$data)
     
     ## -------------------------
     # method 'add_activity'
     ## -------------------------
     
     my_triact$add_activity()
     
     # inspect result
     head(my_triact$data)
     
     ## -------------------------
     # method 'summarize_intervals'
     ## -------------------------
     
     int_summary <- my_triact$summarize_intervals()
     
     # inspect result
     head(int_summary)
     
     ## -------------------------
     # method 'summarize_bouts'
     ## -------------------------
     
     bouts_summary <- my_triact$summarize_bouts()
     
     # inspect result
     head(bouts_summary)
     
     ## -------------------------
     # method 'extract_liedown'
     ## -------------------------
     
     l_downs <- my_triact$extract_liedown()
     
     # inspect result
     print(l_downs)
     
     ## -------------------------
     # method 'extract_standup'
     ## -------------------------
     
     st_ups <- my_triact$extract_standup()
     
     # inspect result
     print(st_ups)
     
     ## -------------------------
     # method 'clone'
     ## -------------------------
     
     # create a Triact object
     my_triact <- Triact$new()
     
     my_triact$load_table(cows_5hz)
     
     # create a complete copy
     my_triact_cp = my_triact$clone(deep = TRUE)
     

cows_5hz                package:triact                 R Documentation

_C_o_w _a_c_c_e_l_e_r_a_t_i_o_n _d_a_t_a

_D_e_s_c_r_i_p_t_i_o_n:

     Acceleration data collected with triaxial accelerometers (MSR145,
     MSR Electronics, Switzerland) attached to the left hind leg of two
     dairy cows (cow01, cow02). The accelerometer sampling frequency
     was 5 Hz. The _forward_, _up_, and _right_ acceleration correspond
     to body relative directions as used in _triact_ (see
     'vignette("introduction", package = "triact")' and Simmler &
     Brouwers, 2024).

       _colname_  _type_   _description_                                 
       id         Factor   unique id for the cow                         
       time       POSIXct  timestamp                                     
       acc_fwd    numeric  acceleration from _forward_ axis (units: _g_) 
       acc_up     numeric  acceleration from _up_ axis (units: _g_)      
       acc_right  numeric  acceleration from _right_ axis (units: _g_)   
      
_U_s_a_g_e:

     cows_5hz
     
_N_o_t_e:

     From the raw data files distributed with the triact package,
     'cows_5hz' can be reproduced as follows:

     # create a Triact object
     my_triact <- Triact$new()
     
     input_dir <- system.file("extdata", package = "triact")
     
     # load data from files
     # note the mapping of XYZ to forward, up, right (parameter timeFwdUpRight_cols)
     
     my_triact$load_files(input = input_dir,
                          id_substring = c(1, 5),
                          timeFwdUpRight_cols = c(1, -2, 3, -4),
                          tz = "Europe/Zurich",
                          skip = "DATA")
     
     cows_5hz_recreated <- my_triact$data
     
     # test whether they are identical
     identical(cows_5hz_recreated, cows_5hz)
     
_S_o_u_r_c_e:

     Agroscope, 8356 Ettenhausen, Switzerland

_R_e_f_e_r_e_n_c_e_s:

     Simmler. M., Brouwers S. P., 2024. _triact_ package for R:
     Analyzing the lying behavior of cows from accelerometer data.
     PeerJ, 12:e17036. doi:10.7717/peerj.17036
     <https://doi.org/10.7717/peerj.17036>



Quitting from introduction.Rmd:232-234 [unnamed-chunk-16]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<error/rlang_error>
Error in `[.data.table`:
! attempt access index 5/5 in VECTOR_ELT
---
Backtrace:
    ▆
 1. └─my_triact$add_lying()
 2.   └─private$filter_acc(...)
 3.     ├─...[]
 4.     └─data.table:::`[.data.table`(...)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Error: processing vignette 'introduction.Rmd' failed with diagnostics:
attempt access index 5/5 in VECTOR_ELT
--- failed re-building ‘introduction.Rmd’

SUMMARY: processing the following file failed:
  ‘introduction.Rmd’

Error: Vignette re-building failed.
Execution halted