% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/io_read.R
\name{ddbs_read_table}
\alias{ddbs_read_table}
\title{Reads a vectorial table from DuckDB into R}
\usage{
ddbs_read_table(conn, name, clauses = NULL, quiet = FALSE)
}
\arguments{
\item{conn}{A \code{DBIConnection} object to a DuckDB database}

\item{name}{A character string of length one specifying the name of the table,
or a character string of length two specifying the schema and table
names. If \code{NULL} (the default), the function returns the result as an
\code{sf} object}

\item{clauses}{character, additional SQL code to modify the query from the
table (e.g. "WHERE ...", "ORDER BY...")}

\item{quiet}{A logical value. If \code{TRUE}, suppresses any informational messages.
Defaults to \code{FALSE}.}
}
\value{
an sf object
}
\description{
Retrieves the data from a DuckDB table, view, or Arrow view with a geometry
column, and converts it to an R \code{sf} object. This function works with
both persistent tables created by \code{ddbs_write_table} and temporary
Arrow views created by \code{ddbs_register_table}.
}
\examples{
\dontrun{
## load packages
library(duckspatial)
library(sf)

# create a duckdb database in memory (with spatial extension)
conn <- ddbs_create_conn(dbdir = "memory")

## create random points
random_points <- data.frame(
  id = 1:5,
  x = runif(5, min = -180, max = 180),
  y = runif(5, min = -90, max = 90)
)

## convert to sf
sf_points <- st_as_sf(random_points, coords = c("x", "y"), crs = 4326)

## Example 1: Write and read persistent table
ddbs_write_vector(conn, sf_points, "points")
ddbs_read_table(conn, "points")

## Example 2: Register and read Arrow view (faster, temporary)
ddbs_register_vector(conn, sf_points, "points_view")
ddbs_read_table(conn, "points_view")

## disconnect from db
ddbs_stop_conn(conn)
}
}
