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

Missing column names in return value of s_attributes() for subcorpora with single cpos pair #249

Open
ChristophLeonhardt opened this issue May 5, 2023 · 0 comments

Comments

@ChristophLeonhardt
Copy link
Contributor

Using GERMAPARLMINI in polmineR v0.8.8.9010 I observed the following unexpected behaviour:

When applying s_attributes() with more than one s-attribute to subcorpora with only one cpos pair, the returned data.table does not have correct column names.

Take the following example:

library(polmineR)
use("polmineR")

corpus("GERMAPARLMINI") |>
  subset(speaker == "Norbert Lammert") |>
  subset(party == "CDU_CSU") |>
  s_attributes(c("speaker", "party"))

Expected would be a data.table with the column names "speaker" and "party". But the return value is a data.table with the column names "V1" and "V2".

After looking at s_attributes.R, I think the issue is that subcorpora with a single cpos pair (or partitions which behave the same) are treated differently from subcorpora with more than one cpos pair, thus losing the name of the s-attributes in the process. This is the part of the code I looked at:

polmineR/R/s_attributes.R

Lines 287 to 290 in db73937

tab <- if (nrow(.Object@cpos) > 1L)
data.table(tab_data)
else
data.table(matrix(tab_data, nrow = 1L))

If there is only one cpos pair, the tab_data object, which still contains the correct names, is turned into a matrix object first which does not have the column names anymore.

Using the dimnames argument of matrix() might be a solution here since tab_data could provide column names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant