Title: Datasets of the CEO (Centre d'Estudis d'Opinio) for Opinion Polls in Catalonia
Version: 1.4.0
Description: Easy and convenient access to the datasets of the "Centre d'Estudis d'Opinio", the Catalan institution for polling and public opinion. The package retrieves microdata directly from the open data platform of the Generalitat de Catalunya and returns it in a tidy format.
Depends: R (≥ 4.1.0)
Imports: tibble, haven, dplyr (≥ 1.0.0), urltools, stringr, jsonlite, lubridate
Suggests: knitr, ggplot2, tidyr (> 1.1.1), curl, rmarkdown, vtable, compareGroups
License: GPL-3
URL: https://ceo.gencat.cat/ca/inici/, https://github.com/ceopinio/CEOdata/
BugReports: https://github.com/ceopinio/CEOdata/issues/
Encoding: UTF-8
RoxygenNote: 7.3.3
VignetteBuilder: knitr
NeedsCompilation: no
Packaged: 2026-03-27 13:24:42 UTC; jardiaca
Author: Xavier Fernández-i-Marín ORCID iD [aut], Joel Ardiaca ORCID iD [aut, cre]
Maintainer: Joel Ardiaca <joelardiacaarnau@gencat.cat>
Repository: CRAN
Date/Publication: 2026-03-27 18:30:09 UTC

CEOdata: CEO microdata access from the Generalitat open data platform

Description

Provides easy and convenient access to microdata from the Centre d'Estudis d'Opinio (CEO). Datasets are retrieved from the open data platform of the Generalitat de Catalunya and returned as tidy tibbles.

Author(s)

Maintainer: Joel Ardiaca joelardiacaarnau@gencat.cat (ORCID)

Authors:

See Also

Useful links:


Import metadata for accumulated microdata series (Dades Obertes)

Description

Returns the catalogue of "microdades acumulades" series published in Dades Obertes (Socrata). Each row corresponds to a series, identified by codi_serie (e.g. "BOP_presencial").

Usage

CEOaccumulated_meta(series = NULL, active_only = FALSE)

Arguments

series

Optional character vector. If provided, filters results to those codi_serie.

active_only

Logical. If TRUE, keeps only series marked as active (best-effort; depends on estat field).

Value

A tibble with the metadata of the accumulated microdata series.

Examples

## Not run: 
m <- CEOaccumulated_meta()
unique(m$codi_serie)

CEOaccumulated_meta(series = "BOP_presencial")

## End(Not run)

Internal cache for accumulated-series metadata

Description

Internal cache for accumulated-series metadata

Usage

CEOaccumulated_metadata()

Import datasets / microdata from the Centre d'Estudis d'Opinio

Description

Easy and convenient access to datasets / microdata from the "Centre d'Estudis d'Opinio". The function can return either: (1) an accumulated microdata series (identified by series), or (2) a single study microdata dataset (identified by reo).

Usage

CEOdata(series = "BOP_presencial", reo = NA, raw = FALSE)

Arguments

series

Character scalar identifying the accumulated series to download. Ignored when reo is provided.

reo

Single REO identifier of a study to download. Can be character, numeric, or factor-like, and is normalized internally.

raw

Logical. If FALSE (default), converts SPSS labelled vectors into factors. If TRUE, returns raw haven-labelled vectors.

Details

Accumulated series are obtained from the Dades Obertes catalogue and are usually identified by codi_serie (e.g. "BOP_presencial").

Value

A tibble with individuals' responses to the requested dataset.

Examples

## Not run: 
# Default: accumulated microdata series
d <- CEOdata()

# Load another accumulated series by code
d_tel <- CEOdata(series = "BOP_telefonica")

# Load a single study by REO
d1145 <- CEOdata(reo = "1145")

## End(Not run)

Import metadata from the "Centre d'Estudis d'Opinio"

Description

Easy and convenient access to the metadata of the "Centre d'Estudis d'Opinio", the Catalan institution for polling and public opinion.

Usage

CEOmeta(
  reo = NULL,
  search = NULL,
  date_start = NA,
  date_end = NA,
  browse = FALSE,
  browse_translate = NULL,
  browse_force = FALSE
)

Arguments

reo

Character vector with one or more REO identifiers. When not NULL it has precedence over search, date_start, and date_end.

search

Character vector with keywords to look for in metadata text fields. Each element is interpreted as one search expression; multiple elements are combined with OR. Matching is case-insensitive.

date_start

Optional start date ("YYYY-MM-DD" or Date) for ⁠Data d'alta al REO⁠.

date_end

Optional end date ("YYYY-MM-DD" or Date) for ⁠Data d'alta al REO⁠.

browse

Logical value. If TRUE, open matching metadata URLs in the browser (up to 10 entries unless browse_force = TRUE).

browse_translate

Optional language code when browse = TRUE: 'oc' (Apertium), or Google-Translate target among 'de', 'en', 'eu', 'gl', 'sp'/'es'.

browse_force

Logical value. If TRUE, bypasses the safety limit of opening at most 10 URLs.

Value

A tibble with the metadata of surveys produced by the CEO.

Examples

## Not run: 
# Retrieve metadata of all surveys:
meta <- CEOmeta()
dim(meta)

# Search for specific terms:
CEOmeta(search = "internet")

# "Medi" AND "Ambient"
CEOmeta(search = "Medi ambient")

# ("Medi" AND "Ambient") OR "Municipi"
CEOmeta(search = c("Medi ambient", "Municipi"))

# Search for entries starting in 2020
CEOmeta(date_start = "2020-01-01")

# Get a specific REO and open its description in browser
CEOmeta(reo = "746", browse = TRUE)

## End(Not run)

Search for keywords in the labels of variables and responses of the survey data

Description

Easy and convenient access to the metadata of the "Centre d'Estudis d'Opinio", the Catalan institution for polling and public opinion. It allows to search for specific terms to obtain the details of the datasets available

Usage

CEOsearch(d, keyword = NULL, where = "variables", translate = FALSE)

Arguments

d

Microdata retrieved from the CEO using the CEOdata() function. It is a data frame with variable labels.

keyword

The character string defining the word / concept to look for within the microdata.

where

A character vector specifying if the function should look amongst variable labels ("variables", default), or amongst value labels ("values").

translate

Logical. When TRUE, it opens a browser with an automatic translation to English of the variable names and labels using Google Translate. Given the specificity of the terms, only the English translation is provided. Defaults to FALSE.

Value

A tibble with the set of variables that match the keyword ("Variable"). If the variables are requested, the second variable is their labels ("Label"), and if the values are required the second on is the value labels ("Value").

Examples

## Not run: 
# Retrieve a dataset to use the function
d <- CEOdata()

# Get the whole set of variable labels
CEOsearch(d)

# Get the whole set of value labels
CEOsearch(d, where = "values")

# Search for specific variable names and variable labels with the string "edat" (age).
CEOsearch(d, keyword = "edat")

# Search for specific variable names and variable labels with the string "edat" (age),
# and translate the results to English.
CEOsearch(d, keyword = "edat", translate = TRUE)

# now for the combination of "valoracio" OR "covid" OR "govern".
CEOsearch(d, keyword = c("valoració", "covid",  "govern"))

## End(Not run)

Detect input type from a path or URL

Description

Detect input type from a path or URL

Usage

ceodata_detect_type(x)

Arguments

x

Character scalar. File path or URL.

Value

One of "sav" or "zip".


Download a remote file to a temporary location

Description

Download a remote file to a temporary location

Usage

ceodata_download(url, quiet = TRUE, timeout = 60)

Arguments

url

Character scalar. Remote URL to download.

quiet

Logical. If TRUE, suppress download progress.

timeout

Numeric. Timeout in seconds (best-effort; depends on download method).

Value

Character scalar path to the downloaded file.


Download and read a dataset from a URL (.sav or .zip containing a single .sav)

Description

Download and read a dataset from a URL (.sav or .zip containing a single .sav)

Usage

ceodata_download_and_read(url, raw = FALSE)

Arguments

url

Character scalar. URL to .sav or .zip.

raw

Logical. If TRUE, do not convert labelled vectors.

Value

A data.frame/tibble.


Read an SPSS .sav file and optionally convert labelled vectors to factors

Description

Read an SPSS .sav file and optionally convert labelled vectors to factors

Usage

ceodata_read_sav(sav_path, raw = FALSE)

Arguments

sav_path

Character scalar. Path to a .sav file.

raw

Logical. If TRUE, return raw haven-labelled vectors without conversion.

Value

A data.frame/tibble as returned by haven::read_spss(), optionally post-processed.


Extract a single .sav file from a zip archive

Description

Extract a single .sav file from a zip archive

Usage

ceodata_sav_from_zip(zip_path)

Arguments

zip_path

Character scalar. Path to a zip file.

Value

Character scalar path to the extracted .sav file (temporary).


Download and prepare the metadata of accumulated microdata series (Dades Obertes)

Description

Source dataset (Socrata): https://analisi.transparenciacatalunya.cat/resource/gp4k-sxxn.json

Usage

getCEOaccumulated_metadata()

Value

A tibble with the accumulated series metadata.


Internal function to properly read the JSON from CEO

Description

Used to address limitations of the JSON format provided.

Usage

read.ceo.json(x)

Arguments

x

JSON data structure


Internal function to get the metadata of CEO surveys into cache

Description

Used when loading the package. It gets the latest metadata of CEO surveys, cleans it and makes it ready for the rest of functions in the package.

Usage

the

Format

An object of class environment of length 0.