makeLabels: Print insect labels

View source: R/makeLabels.R

makeLabelsR Documentation

Print insect labels

Description

Function to print insect labels from a set of csv files. Written for labels used in the U of C insect collection and Galpern lab.

Usage

makeLabels(
  inputPath,
  csvPaths,
  outputPath,
  sepChar = rep(",", 3),
  platform = "Word",
  latLonDigits = c(5, 5),
  skipLines = FALSE
)

Arguments

inputPath

Input file with number of labels needed (csv)

csvPaths

Paths to site and trap tables (vector with 2 paths - csv)

outputPath

Output path (docx)

sepChar

Separator characters for inputPath, site, and trap table csvs (default: rep(',',3))

platform

Character string of platform used for opening docx files: 'Word' (default), 'GoogleDocs', or 'LibreOffice'

latLonDigits

Maximum digits used for latitude and longitude (default: c(5,5))

skipLines

Should missing BLIDs be skipped? (default: FALSE)

Details

inputPath is a path to a csv with the following column headers:

BTID (trapping ID), N (number of labels needed)

csvPaths[1] is a path to the site csv with the following column headers:

BLID, lat, lon, locality, elevation, country, province

csvPaths[2] is a path to the trap csv with the following column headers:

BTID, BLID, collector, trapType, startYear, startMonth (numeric), startDay, endYear, endMonth (numeric), endDay, lonTrap, latTrap, elevTrap

If lonTrap, latTrap, or elevTrap values are missing from csvPaths[2], values will be filled using site csv.

output[1] is a path to a docx file that will be printed. If more than 1 page of labels is required, additional files will be created with numbers appended before the file extension (e.g. labels_01.docx, labels_02.docx)

Examples

# Make csv files for labels

# 2 trapping sessions, with 20 labels each
input <- data.frame(BTID = c('10069-1-A-2015','51273-0-B-2019'),
                    N = c(20,20))

# Site table
site <- data.frame(BLID=c(10069,51273),lat=c(50,51),lon=c(-114,-113),
                   locality=c('Near Town','Near Mountains'),
                   elevation=c(800,1200),country=rep('CANADA',2),
                   province=rep('Alberta',2))

#Trap table - netting has only a single day on label, while blue vane has a
#date range
trap <- data.frame(BTID=c('10069-1-A-2015','51273-0-B-2019'),
                   BLID=c(10069,51273),collector=c('D. Smith','L. Robbins'),
                   trapType=c('Blue Vane','Netting'),
                   startYear=c(2012,2021),startMonth=c(6,7),startDay=c(10,20),
                   endYear=c(2012,NA),endMonth=c(6,NA),endDay=c(15,NA),
                   lonTrap=c(-114.5,-113.1),latTrap=c(51,52.3),
                   elevTrap=c(815,1231))

#Write csvs to file
write.csv(input,'inputcsv.csv')
write.csv(site,'sitecsv.csv')
write.csv(trap,'trapcsv.csv')

#Create labels
makeLabels(inputPath = 'inputcsv.csv',
           csvPaths = c('sitecsv.csv','trapcsv.csv'),
           outputPath = 'labelSheet.docx',
           platform = 'Word'
)

#Same thing, but with 2 pages of labels - takes a few mins
input$N <- c(100,100)

write.csv(input,'inputcsv.csv')

makeLabels(inputPath = 'inputcsv.csv',
           csvPaths = c('sitecsv.csv','trapcsv.csv'),
           outputPath = 'labelSheet.docx',
           platform = 'Word'
)

samuelVJrobinson/SRtools documentation built on Nov. 11, 2024, 12:37 p.m.