Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

format_SQL_in_statement

Format vector of values into a string suitable for an SQL IN statement.


Description

Concatenate a vector to SQL IN-compatible syntax: letters[1:3] becomes ('a','b','c'). Values in x are first passed through unique().

Usage

format_SQL_in_statement(x)

Arguments

x

A character vector.

Value

A character vector (unit length) containing concatenated group syntax for use in SQL IN, with unique value found in x.

Note

Only character output is supported.

Examples

library(aqp)

# get some mukeys
q <- "select top(2) mukey from mapunit;"
mukeys <- SDA_query(q)

# format for use in an SQL IN statement
mukey.inst <- format_SQL_in_statement(mukeys$mukey)
mukey.inst

# make a more specific query: for component+horizon data, just for those mukeys
q2 <- sprintf("SELECT * FROM mapunit
               INNER JOIN component ON mapunit.mukey = component.mukey
               INNER JOIN chorizon ON component.cokey = chorizon.cokey
               WHERE mapunit.mukey IN %s;", mukey.inst)
# do the query
res <- SDA_query(q2)

# build a SoilProfileCollection from horizon-level records
depths(res) <- cokey ~ hzdept_r + hzdepb_r

# normalize mapunit/component level attributes to site-level for plot
site(res) <- ~ muname + mukey + compname + comppct_r + taxclname

# make a nice label
res$labelname <- sprintf("%s (%s%s)", res$compname, res$comppct_r, "%")

# major components only
res <- subset(res, comppct_r >= 85)

# inspect plot of result
par(mar=c(0,0,0,0))
groupedProfilePlot(res, groups = "mukey", color = "hzname", cex.names=0.8,
                   id.style = "side", label = "labelname")

soilDB

Soil Database Interface

v2.6.1
GPL (>= 3)
Authors
Dylan Beaudette [aut], Jay Skovlin [aut], Stephen Roecker [aut], Andrew Brown [aut, cre]
Initial release
2021-04-7

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.