Skip to content

Commit a327ac2

Browse files
authored
Merge pull request #35 from antaldaniel/master
harmonising with the dataset package
2 parents 3a6dbbb + bfba881 commit a327ac2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+997
-420
lines changed

.github/workflows/rhub.yaml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# R-hub's generic GitHub Actions workflow file. It's canonical location is at
2+
# https://github.com/r-hub/actions/blob/v1/workflows/rhub.yaml
3+
# You can update this file to a newer version using the rhub2 package:
4+
#
5+
# rhub::rhub_setup()
6+
#
7+
# It is unlikely that you need to modify this file manually.
8+
9+
name: R-hub
10+
run-name: "${{ github.event.inputs.id }}: ${{ github.event.inputs.name || format('Manually run by {0}', github.triggering_actor) }}"
11+
12+
on:
13+
workflow_dispatch:
14+
inputs:
15+
config:
16+
description: 'A comma separated list of R-hub platforms to use.'
17+
type: string
18+
default: 'linux,windows,macos'
19+
name:
20+
description: 'Run name. You can leave this empty now.'
21+
type: string
22+
id:
23+
description: 'Unique ID. You can leave this empty now.'
24+
type: string
25+
26+
jobs:
27+
28+
setup:
29+
runs-on: ubuntu-latest
30+
outputs:
31+
containers: ${{ steps.rhub-setup.outputs.containers }}
32+
platforms: ${{ steps.rhub-setup.outputs.platforms }}
33+
34+
steps:
35+
# NO NEED TO CHECKOUT HERE
36+
- uses: r-hub/actions/setup@v1
37+
with:
38+
config: ${{ github.event.inputs.config }}
39+
id: rhub-setup
40+
41+
linux-containers:
42+
needs: setup
43+
if: ${{ needs.setup.outputs.containers != '[]' }}
44+
runs-on: ubuntu-latest
45+
name: ${{ matrix.config.label }}
46+
strategy:
47+
fail-fast: false
48+
matrix:
49+
config: ${{ fromJson(needs.setup.outputs.containers) }}
50+
container:
51+
image: ${{ matrix.config.container }}
52+
53+
steps:
54+
- uses: r-hub/actions/checkout@v1
55+
- uses: r-hub/actions/platform-info@v1
56+
with:
57+
token: ${{ secrets.RHUB_TOKEN }}
58+
job-config: ${{ matrix.config.job-config }}
59+
- uses: r-hub/actions/setup-deps@v1
60+
with:
61+
token: ${{ secrets.RHUB_TOKEN }}
62+
job-config: ${{ matrix.config.job-config }}
63+
- uses: r-hub/actions/run-check@v1
64+
with:
65+
token: ${{ secrets.RHUB_TOKEN }}
66+
job-config: ${{ matrix.config.job-config }}
67+
68+
other-platforms:
69+
needs: setup
70+
if: ${{ needs.setup.outputs.platforms != '[]' }}
71+
runs-on: ${{ matrix.config.os }}
72+
name: ${{ matrix.config.label }}
73+
strategy:
74+
fail-fast: false
75+
matrix:
76+
config: ${{ fromJson(needs.setup.outputs.platforms) }}
77+
78+
steps:
79+
- uses: r-hub/actions/checkout@v1
80+
- uses: r-hub/actions/setup-r@v1
81+
with:
82+
job-config: ${{ matrix.config.job-config }}
83+
token: ${{ secrets.RHUB_TOKEN }}
84+
- uses: r-hub/actions/platform-info@v1
85+
with:
86+
token: ${{ secrets.RHUB_TOKEN }}
87+
job-config: ${{ matrix.config.job-config }}
88+
- uses: r-hub/actions/setup-deps@v1
89+
with:
90+
job-config: ${{ matrix.config.job-config }}
91+
token: ${{ secrets.RHUB_TOKEN }}
92+
- uses: r-hub/actions/run-check@v1
93+
with:
94+
job-config: ${{ matrix.config.job-config }}
95+
token: ${{ secrets.RHUB_TOKEN }}

DESCRIPTION

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Depends:
2929
R (>= 3.5.0)
3030
Imports:
3131
assertthat,
32+
dataset,
3233
dplyr (>= 1.0.0),
3334
fs,
3435
glue,
@@ -56,13 +57,14 @@ Suggests:
5657
png,
5758
rmarkdown,
5859
spelling,
60+
statcodelists,
5961
testthat (>= 3.0.0)
6062
VignetteBuilder:
6163
knitr
6264
Config/testthat/edition: 3
6365
Encoding: UTF-8
6466
Language: en-US
6567
LazyData: true
66-
RoxygenNote: 7.2.3
68+
RoxygenNote: 7.3.2
6769
X-schema.org-isPartOf: http://ropengov.org/
6870
X-schema.org-keywords: ropengov

NAMESPACE

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
# Generated by roxygen2: do not edit by hand
22

33
S3method("[",retroharmonize_labelled_spss_survey)
4+
S3method("names<-",retroharmonize_labelled_spss_survey)
45
S3method(format,retroharmonize_labelled_spss_survey)
56
S3method(is.na,retroharmonize_labelled_spss_survey)
67
S3method(levels,retroharmonize_labelled_spss_survey)
8+
S3method(mean,retroharmonize_labelled_spss_survey)
9+
S3method(median,retroharmonize_labelled_spss_survey)
10+
S3method(obj_print_footer,retroharmonize_labelled_spss_survey)
711
S3method(obj_print_header,retroharmonize_labelled_spss_survey)
12+
S3method(print,survey_df)
813
S3method(quantile,retroharmonize_labelled_spss_survey)
14+
S3method(sum,retroharmonize_labelled_spss_survey)
915
S3method(summary,retroharmonize_labelled_spss_survey)
1016
S3method(summary,survey)
1117
S3method(vec_cast,character.retroharmonize_labelled_spss_survey)
@@ -17,6 +23,7 @@ S3method(vec_ptype2,retroharmonize_labelled_spss_survey.double)
1723
S3method(vec_ptype2,retroharmonize_labelled_spss_survey.retroharmonize_labelled_spss_survey)
1824
S3method(vec_ptype_abbr,retroharmonize_labelled_spss_survey)
1925
S3method(vec_ptype_full,retroharmonize_labelled_spss_survey)
26+
S3method(weighted.mean,retroharmonize_labelled_spss_survey)
2027
export("%>%")
2128
export(as_character)
2229
export(as_factor)
@@ -45,6 +52,7 @@ export(is.crosswalk_table)
4552
export(is.labelled_spss_survey)
4653
export(is.na_range_to_values)
4754
export(is.survey)
55+
export(is.survey_df)
4856
export(label_normalize)
4957
export(labelled_spss_survey)
5058
export(merge_surveys)
@@ -63,11 +71,19 @@ export(subset_save_surveys)
6371
export(subset_surveys)
6472
export(subset_waves)
6573
export(survey)
74+
export(survey_df)
6675
export(val_label_normalize)
6776
export(var_label_normalize)
6877
import(rlang)
6978
import(vctrs)
7079
importFrom(assertthat,assert_that)
80+
importFrom(dataset,`subject<-`)
81+
importFrom(dataset,datacite)
82+
importFrom(dataset,dataset_df)
83+
importFrom(dataset,dublincore)
84+
importFrom(dataset,is.dataset_df)
85+
importFrom(dataset,subject)
86+
importFrom(dataset,subject_create)
7187
importFrom(dplyr,across)
7288
importFrom(dplyr,all_of)
7389
importFrom(dplyr,any_of)
@@ -111,11 +127,13 @@ importFrom(haven,read_sav)
111127
importFrom(haven,read_spss)
112128
importFrom(haven,write_sav)
113129
importFrom(here,here)
130+
importFrom(labelled,`var_label<-`)
114131
importFrom(labelled,labelled)
115132
importFrom(labelled,labelled_spss)
116133
importFrom(labelled,na_range)
117134
importFrom(labelled,na_values)
118135
importFrom(labelled,to_character)
136+
importFrom(labelled,to_labelled)
119137
importFrom(labelled,val_labels)
120138
importFrom(labelled,var_label)
121139
importFrom(magrittr,"%>%")

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
# retroharmonize 0.2.6
2+
13
# retroharmonize 0.2.5
2-
* New article [Creating a Harmonized Cultural Access & Participation Dataset for Music](https://retroharmonize.dataobservatory.eu/articles/cap.html)
34
* Unified function interface and parameter names.
45
* This development version has a few known [issues](https://github.com/rOpenGov/retroharmonize/issues).
56

R/assertions.R

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#' @keywords internal
22
validate_survey_list <- function(survey_list) {
33

4-
54
assert_that(!is.null(survey_list),
65
msg = "The parameter 'survey_list' is NULL.")
76

@@ -51,16 +50,16 @@ validate_survey_list <- function(survey_list) {
5150

5251
duplicate_ids <- ids[duplicated (ids )]
5352
duplicate_filenames <- filenames[duplicated (filenames)]
54-
53+
5554
assert_that(length(duplicate_ids)==0,
5655
msg = paste0(
57-
paste(duplicate_ids),
56+
paste(duplicate_ids, collapse = ", "),
5857
" are not unique."
5958
))
6059

6160
assert_that(length(duplicate_filenames)==0,
6261
msg = paste0(
63-
paste(duplicate_filenames),
62+
paste(duplicate_filenames, collapse = ", "),
6463
" are not unique."
6564
))
6665
}
@@ -81,18 +80,6 @@ validate_survey_files <- function(survey_files) {
8180
TRUE
8281
}
8382

84-
#' @importFrom assertthat assert_that
85-
#' @importFrom fs is_file
86-
#' @keywords internal
87-
valid_file_info <- function(file) {
88-
assertthat::assert_that(
89-
fs::is_file(file),
90-
msg = paste0("file='", file, "' is not a file. ")
91-
)
92-
93-
file.info(file)
94-
}
95-
9683
#' @title Validate harmonize_labels parameter
9784
#' Check if "from", "to", and "numeric_values" are of equal lengths.
9885
#' @importFrom dplyr select

R/codebook.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#' # This is a new function candidate and is not written yet.
1010
#' codebook_create()
1111

12+
#' @keywords internal
1213
codebook_create <- function() {
13-
NULL
14+
cat("Not written yet")
1415
}

R/harmonize_values.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#' @param id A survey ID, defaults to \code{survey_id}
2222
#' @param remove Defaults to \code{NULL}. A character or regex that will be removed from all
2323
#' old value labels, like \code{"\\("|\\)} for ( and ).
24-
#' @param perl Use perl-like regex? Defaults to {FALSE}.
24+
#' @param perl Use perl-like regex? Defaults to \code{FALSE}.
2525
#' @importFrom labelled to_character labelled na_values val_labels
2626
#' @importFrom labelled var_label
2727
#' @importFrom tibble tibble as_tibble

R/labelled_spss_survey.R

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ obj_print_header.retroharmonize_labelled_spss_survey <- function(x, ...) {
207207
invisible(x)
208208
}
209209

210+
#' @export
210211
obj_print_footer.retroharmonize_labelled_spss_survey <- function(x, ...) {
211212
print_attributes(x)
212213
invisible(x)
@@ -276,16 +277,20 @@ as_factor <- function(x, levels = "default", ordered = FALSE) {
276277
tmp
277278
}
278279

279-
#' @export
280+
#' @rdname labelled_spss_survey
281+
#' @exportS3Method
280282
levels.retroharmonize_labelled_spss_survey <- function(x) {
281283
NULL
282284
}
283285

284-
`names<-.retroharmonize_labelled_spss_survey` <- function(x, value) {
286+
#' @rdname labelled_spss_survey
287+
#' @export
288+
"names<-.retroharmonize_labelled_spss_survey" <- function(x, value) {
285289
attr(x, "names") <- value
286290
x
287291
}
288292

293+
#' @rdname labelled_spss_survey
289294
#' @importFrom haven format_tagged_na
290295
#' @export
291296
format.retroharmonize_labelled_spss_survey <- function(x, ..., digits = getOption("digits")) {
@@ -345,7 +350,9 @@ vec_convert_na <- function(x) {
345350
vctrs::vec_data(x))
346351
}
347352

353+
#' @rdname labelled_spss_survey
348354
#' @importFrom stats median
355+
#' @export
349356
median.retroharmonize_labelled_spss_survey <- function(x, na.rm = TRUE, ...) {
350357
if (is.character(x)) {
351358
abort("Can't compute median of labelled_spss_survey<character>")
@@ -354,6 +361,7 @@ median.retroharmonize_labelled_spss_survey <- function(x, na.rm = TRUE, ...) {
354361
median(vec_convert_na(x), na.rm = TRUE, ...)
355362
}
356363

364+
#' @rdname labelled_spss_survey
357365
#' @importFrom stats quantile
358366
#' @export
359367
quantile.retroharmonize_labelled_spss_survey <- function(x, probs, ...) {
@@ -363,7 +371,9 @@ quantile.retroharmonize_labelled_spss_survey <- function(x, probs, ...) {
363371
quantile(vec_convert_na(x), probs, na.rm = TRUE, ...)
364372
}
365373

374+
#' @rdname labelled_spss_survey
366375
#' @importFrom stats weighted.mean
376+
#' @exportS3Method
367377
weighted.mean.retroharmonize_labelled_spss_survey <- function(x, w, ...) {
368378
if (is.character(x)) {
369379
abort("Can't compute median of labelled_spss_survey<character>")
@@ -376,6 +386,8 @@ weighted.mean.retroharmonize_labelled_spss_survey <- function(x, w, ...) {
376386
weighted.mean(vec_convert_na(x), w, na.rm = TRUE, ...)
377387
}
378388

389+
#' @rdname labelled_spss_survey
390+
#' @exportS3Method
379391
mean.retroharmonize_labelled_spss_survey <- function(x, ...) {
380392
if (is.character(x)) {
381393
abort("Can't compute mean of labelled_spss_survey<character>")
@@ -384,7 +396,8 @@ mean.retroharmonize_labelled_spss_survey <- function(x, ...) {
384396
mean(vec_convert_na(x), ...)
385397
}
386398

387-
399+
#' @rdname labelled_spss_survey
400+
#' @exportS3Method
388401
sum.retroharmonize_labelled_spss_survey <- function(x, ...) {
389402
if (is.character(x)) {
390403
abort("Can't compute sum of labelled_spss_survey<character>")

R/metadata_create.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ metadata_survey_create <- function(survey) {
125125
filename <- attr(survey, "filename")
126126

127127
if (is.null(filename)) filename <- "unknown"
128-
id <- attr(survey, "id")
128+
129+
id <- ifelse(is.null(attr(survey, "id")), attr(survey, "identifier"), attr(survey, "id"))
129130
if (is.null(id)) id <- "missing"
130131

131132
if( ncol(survey) == 0) {
@@ -138,7 +139,7 @@ metadata_survey_create <- function(survey) {
138139

139140
class_orig <- vapply( survey, function(x) class(x)[1], character(1))
140141

141-
metadata <- tibble::tibble (
142+
metadata <- tibble (
142143
filename = filename,
143144
id = id,
144145
var_name_orig = names(survey),
@@ -249,7 +250,7 @@ metadata_survey_create <- function(survey) {
249250
select ( -label_type )
250251
}
251252

252-
253+
# -----------------------------------------------------------------------
253254
#' @title Initialize a metadata data frame
254255
#'
255256
#' @inheritParams metadata_create

0 commit comments

Comments
 (0)