Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #662 #663

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/as-data-frame.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
paste0(unique(names(ds_out)[dup_csv_names]), collapse = ", ")
)
}
return(csvToDataFrame(ds_out, x, parsing_info, array_strategy, categorical.mode = attr(x, "mode")))

Check warning on line 132 in R/as-data-frame.R

View workflow job for this annotation

GitHub Actions / test-coverage

file=R/as-data-frame.R,line=132,col=101,[line_length_linter] Lines should not be more than 100 characters. This line is 103 characters.

Check warning on line 132 in R/as-data-frame.R

View workflow job for this annotation

GitHub Actions / test-coverage

file=R/as-data-frame.R,line=132,col=101,[line_length_linter] Lines should not be more than 100 characters. This line is 103 characters.
}

csvColInfo <- function(ds, verbose = TRUE) {
Expand All @@ -138,7 +138,7 @@
flattened_meta <- flattenVariableMetadata(meta)

orig_aliases <- aliases(flattened_meta)
parent_aliases <- vapply(flattened_meta, function(x) x$parent_alias %||% NA_character_, character(1))

Check warning on line 141 in R/as-data-frame.R

View workflow job for this annotation

GitHub Actions / test-coverage

file=R/as-data-frame.R,line=141,col=101,[line_length_linter] Lines should not be more than 100 characters. This line is 105 characters.

Check warning on line 141 in R/as-data-frame.R

View workflow job for this annotation

GitHub Actions / test-coverage

file=R/as-data-frame.R,line=141,col=101,[line_length_linter] Lines should not be more than 100 characters. This line is 105 characters.
qualified_aliases <- ifelse(
is.na(parent_aliases),
orig_aliases,
Expand All @@ -159,7 +159,7 @@
if (verbose) {
msg_rows <- out$cond_qualified_alias != out$orig_alias
if (any(msg_rows)) {
alias_info <- paste0(out$orig_alias[msg_rows], " -> ", out$cond_qualified_alias[msg_rows])

Check warning on line 162 in R/as-data-frame.R

View workflow job for this annotation

GitHub Actions / test-coverage

file=R/as-data-frame.R,line=162,col=101,[line_length_linter] Lines should not be more than 100 characters. This line is 102 characters.

Check warning on line 162 in R/as-data-frame.R

View workflow job for this annotation

GitHub Actions / test-coverage

file=R/as-data-frame.R,line=162,col=101,[line_length_linter] Lines should not be more than 100 characters. This line is 102 characters.
message(
"Some column names are qualified because there were duplicate aliases ",
"in dataset:\n", paste0(alias_info, collapse = ", ")
Expand All @@ -179,7 +179,7 @@
array_strategy <- match.arg(array_strategy)
meta <- attr(parsing_info, "meta")
## CrunchDataFrames contain both server variables and local variables.
var_order <- if (inherits(cr_data, "CrunchDataFrame")) names(cr_data) else aliases(allVariables(cr_data))

Check warning on line 182 in R/as-data-frame.R

View workflow job for this annotation

GitHub Actions / test-coverage

file=R/as-data-frame.R,line=182,col=101,[line_length_linter] Lines should not be more than 100 characters. This line is 109 characters.

Check warning on line 182 in R/as-data-frame.R

View workflow job for this annotation

GitHub Actions / test-coverage

file=R/as-data-frame.R,line=182,col=101,[line_length_linter] Lines should not be more than 100 characters. This line is 109 characters.
## Iterate over the names of cr_data to preserve the desired order.
## Nest everything in an extra layer of lists because one layer is removed
out <- unlist(lapply(var_order, function(a) {
Expand All @@ -195,12 +195,12 @@
} else {
cp <- columnParser("categorical")
}
subvar_info <- parsing_info[!is.na(parsing_info$parent_alias) & parsing_info$parent_alias == alias(v), ]

Check warning on line 198 in R/as-data-frame.R

View workflow job for this annotation

GitHub Actions / test-coverage

file=R/as-data-frame.R,line=198,col=101,[line_length_linter] Lines should not be more than 100 characters. This line is 116 characters.

Check warning on line 198 in R/as-data-frame.R

View workflow job for this annotation

GitHub Actions / test-coverage

file=R/as-data-frame.R,line=198,col=101,[line_length_linter] Lines should not be more than 100 characters. This line is 116 characters.
cols <- csv_df[, subvar_info$qualified_alias]
cols <- csv_df[, subvar_info$qualified_alias, drop = FALSE]
if (array_strategy == "alias"){
return(structure(lapply(cols, cp, v, categorical.mode), .Names = subvar_info$cond_qualified_alias))

Check warning on line 201 in R/as-data-frame.R

View workflow job for this annotation

GitHub Actions / test-coverage

file=R/as-data-frame.R,line=201,col=101,[line_length_linter] Lines should not be more than 100 characters. This line is 115 characters.

Check warning on line 201 in R/as-data-frame.R

View workflow job for this annotation

GitHub Actions / test-coverage

file=R/as-data-frame.R,line=201,col=101,[line_length_linter] Lines should not be more than 100 characters. This line is 115 characters.
} else if (array_strategy == "qualified_alias") {
return(structure(lapply(cols, cp, v, categorical.mode), .Names = subvar_info$qualified_alias))

Check warning on line 203 in R/as-data-frame.R

View workflow job for this annotation

GitHub Actions / test-coverage

file=R/as-data-frame.R,line=203,col=101,[line_length_linter] Lines should not be more than 100 characters. This line is 110 characters.

Check warning on line 203 in R/as-data-frame.R

View workflow job for this annotation

GitHub Actions / test-coverage

file=R/as-data-frame.R,line=203,col=101,[line_length_linter] Lines should not be more than 100 characters. This line is 110 characters.
} else { # array_strategy==packed
# Extra list layer to hold the array variable's alias
return(structure(
Expand All @@ -217,7 +217,7 @@
}
} else {
type <- type(v)
cp <- switch(type, "numeric" = numericCsvParser, "text" = textCsvParser, columnParser(type))

Check warning on line 220 in R/as-data-frame.R

View workflow job for this annotation

GitHub Actions / test-coverage

file=R/as-data-frame.R,line=220,col=101,[line_length_linter] Lines should not be more than 100 characters. This line is 104 characters.

Check warning on line 220 in R/as-data-frame.R

View workflow job for this annotation

GitHub Actions / test-coverage

file=R/as-data-frame.R,line=220,col=101,[line_length_linter] Lines should not be more than 100 characters. This line is 104 characters.
return(structure(list(cp(csv_df[[a]], v, categorical.mode)), .Names = a))
}
}), recursive = FALSE)
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-as-data-frame.R
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,16 @@ with_mock_crunch({
expect_equivalent(df_packed, expected_packed_df)
})

test_that("csvToDataFrame handles 1 column subvariables", {
csv_df <- structure(list(`x[x1]` = 1:3, `x[x2_derived]` = 1:3, `y[y1]` = 1:3), class = "data.frame", row.names = c(NA, -3L))
expected <- data.frame(`x[x1]` = 1:3, `x2_derived` = 1:3, `y[y1]` = factor(letters[1:3], levels = letters[1:5]), check.names = FALSE)
col_info <- csvColInfo(ds_dup)

df_actual <- csvToDataFrame(csv_df, ds_dup, col_info[6:8, ])[c("x[x1]", "x2_derived", "y[y1]")]

expect_equal(df_actual, expected)
})

test_that("as.data.frame when a variable has an apostrophe in its alias", {
t2 <- forceVariableCatalog(ds)

Expand Down
Loading