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

Specifically, the following code should suffice:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
library(tidyverse)
library(raster)

# 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 = do.call("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 %>%
        as.data.frame(),
    point.values %>%
        as.data.frame() %>%
        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")