| getID {RFishBC} | R Documentation |
Extracts a fish identification from a vector of image file names
Description
This returns a vector of fish identification values from a vector of image file names.
Usage
getID(x, IDpattern, IDreplace, ...)
Arguments
x |
A charachter vector of image file names. |
IDpattern |
A regular expression used to extract the fish identification value from the image file names in |
IDreplace |
A string to replace the expression matched in |
... |
Parameters to be given to |
Details
By default it is assumed that the ID value follows an underscore at the end/tail of image file name (sans extension). Other patterns can be used by giving a suitable regular expression to IDpattern and possibly a replacement (usually a group identifier such as “\1”) in IDreplace. You may find the webpage at spannbaueradam.shinyapps.io/r_regex_tester/ useful for identifying the necessary regular expression pattern for your situation.
If the pattern in IDpattern does not exist in each element of x then an error will be returned. In other words, the fish identification value must be in the same “place” (based on IDpattern) in EVERY image filename.
If the vector of returned IDs contains any duplicated values then a warning will be issued.
The list of image file names in a given folder/directory may be obtained with listFiles.
Value
Character vector.
Author(s)
Derek H. Ogle, DerekOgle51@gmail.com
See Also
listFiles and digitizeRadii.
Examples
## These are possible vectors of image file names with the fish ID after
## the last underscore ... which is the default behavior
ex1 <- c("Scale_1.jpg","Scale_2.jpg")
ex2 <- c("Kiyi_472.bmp","Kiy_567.jpg")
ex3 <- c("PWF_MI345.tiff","PWF_WI567.tiff")
ex4 <- c("LKT_oto_23.jpg","LKT_finray_34.jpg")
## These are extracted fish IDs
getID(ex1)
getID(ex2)
getID(ex3)
getID(ex4)
## These are possible vectors of image file names with the fish ID NOT after
## the last underscore. This requires judicious use of IDpattern= and
## IDreplace= (similar to pattern= and replacement- as used in sub()).
### fish ID at the beginning of the name
ex5 <- c("1_Scale.jpg","2_Scale.jpg")
getID(ex5,IDpattern="\\_.*")
### fish ID between two underscores (might be used if multiple images for one ID)
ex6 <- c("DWS_100_1.jpg","DWS_101_2,jpg")
getID(ex6,IDpattern=".*\\_(.+?)\\_.*",IDreplace="\\1")
ex7 <- c("DWS_MI100_1.jpg","DWS_MI100_2,jpg")
getID(ex7,IDpattern=".*\\_(.+?)\\_.*",IDreplace="\\1")
### Will be warned if the returned IDs are not unique
## Not run:
ex8 <- c("Ruffe_456.jpg","Ruffe_456.jpg","Ruffe_567.jpg")
getID(ex8)
## End(Not run)