Calculates sample bottle volumes for a given USGS station and storm event(s)

Package Status

|Linux|Test Coverage| USGS Status | |----------|------------|------------| | travis|Coverage Status|status|

Reporting bugs

Please consider reporting bugs and asking questions on the Issues page:

Code of Conduct

We want to encourage a warm, welcoming, and safe environment for contributing to this project. See the code of conduct for more information.

Installation of R and RStudio

This section should only need to be done once per computer.

The following link walks you through an installation of R and RStudio:

Installation Instructions

If you follow those instructions exactly, you should have the USGS R repository (GRAN) added to your R profile. If that step doesn't ring a bell, paste the following into your R console:

rprofile_path = file.path(Sys.getenv("HOME"), ".Rprofile")
      append =  TRUE)

cat('Your Rprofile has been updated to include GRAN.
    Please restart R for changes to take effect.')


Useful links:

Installation of SampleSplitting

This section should also only have to be done once. It assumes the USGS R repository (GRAN) was added to your R profile as described above.


Regularly, it is a good idea to update ALL your packages in R. If using RStudio, this is quite easy, there's an Update button in the "Packages" tab. This checks CRAN and GRAN for updates. It is a good idea to click this update regularly.


An example workflow script is available at or in your R package library (eg C:\Users\jlthomps\Documents\R\win-library\2.14\SampleSplitting\sampleSplitWorkflow.R)

Explanation of the calculations in the labDataOut function follow:

Sample Splitting

User enters data, storm start and end dates, max bottle volumes, max sample volumes, storm names and sub nums (optional) For each storm: Discharge data is subset to one value after the storm end date and one value before the storm start date Storm discharge data is subset to only non-null discharge values Volumes are calculated for each discharge value if row 1, volume is NA if last row, volume is NA else volume is (.5(adaps_data_storm$datetime[i]-adaps_data_storm$datetime[i-1])(.75adaps_data_storm$X02_00060[i]+.25adaps_data_storm$X02_00060[i-1]))+(.5(adaps_data_storm$datetime[i+1],adaps_data_storm$datetime[i])(.75adaps_data_storm$X02_00060[i]+.25adaps_data_storm$X02_00060[i+1])) Samples data is subset to only <= storm end date and >= storm start date If there are no sample rows within the designated storm start and end dates, "Storm event specified which has no samples" is output If sub nums were entered, the bottle numbers are set to begin with the designated number If removeDate(s) were input, those samples are removed from the samples data subset For each sample: if row 1, sampStart is minimum date from Discharge data subset if not row 1, sampStart is adaps_samp_storm$datetime[i-1]+(.5(adaps_samp_storm$datetime[i]-adaps_samp_storm$datetime[i-1])) if last row, sampEnd is maximum date from Discharge data subset if not last row, sampEnd is adaps_samp_storm$datetime[i]+(.5(adaps_samp_storm$datetime[i+1]-adaps_samp_storm$datetime[i])) Sample volume subset is defined as discharge data >= sampStart and <= sampEnd if sampEnd corresponds to an exact discharge value datetime, that volume is multiplied by 1/2 if sampStart corresponds to an exact discharge value datetime, the first row of the existing Sample Volume subset is reduced to half the volume value, because it is a split discharge volume for each sample is sum(Sample_volume_subset$volume) Percent for each sample is round(100(adaps_samp_storm$volume/sum(adaps_data_storm$volume,na.rm=TRUE)) mL for each sample is adaps_samp_storm$volumemaxBottleV/max(adaps_samp_storm$volume) If sum(mL)>maxSampV mL values are all multipled by the ratio of maxSampV/sum(mL) mL values are truncated (not rounded, b/c we don't want to go over allowable lab volume) else mL values are truncated trunc(adaps_samp_storm$mL*(maxSampV/sum(adaps_samp_storm$mL))


This software is in the public domain because it contains materials that originally came from the U.S. Geological Survey, an agency of the United States Department of Interior. For more information, see the official USGS copyright policy at

Although this software program has been used by the U.S. Geological Survey (USGS), no warranty, expressed or implied, is made by the USGS or the U.S. Government as to the accuracy and functioning of the program and related program material nor shall the fact of distribution constitute any such warranty, and no responsibility is assumed by the USGS in connection therewith.

This software is provided "AS IS."

USGS-R/SampleSplitting documentation built on Aug. 5, 2017, 2:07 p.m.