To extract e.g. bioclim variables from raster files, use raster::extract.

Specifically, the following code should suffice:


# First, form a raster stack from all 19 bioclim variables
load_bioclim = function(i) {
    raster(sprintf("WorldClim2/wc2.0_bio_30s_%02d.tif", i),
           varname=sprintf("Bio%02d", i)))
rasters ="stack", lapply(1:19, load_bioclim))

# Load point data e.g. sample accession metadata
meta.geo = read_csv("path/to/metadata.csv")

# Let raster/sp know which columns are lat & long. longitude and latitude below
# are column names of meta.geo
coordinates(meta.geo) = ~ longitude + latitude

# Extract value of each raster layer for each point in meta.geo using
# raster::extract
point.values = extract(rasters, meta.geo)

# Bring it all together: meta.geo is now an sp data table, and point.values is
# a matrix. We convert both to dataframes, rename the extracted point value
# columns from the filename to the bioclim variable name, and then join the columns
# together and write it out.
meta.env =  bind_cols(
    metadata %>%,
    point.values %>% %>%
        rename_with(function(x) gsub("wc2.0_bio_30s_([0-9]+)", "Bio\\1", x, perl=T))
write_tsv(meta.env, "path/to/metadata-env.tsv")