0

I imported a database thanks to read.table function from a .txt file in R. Here is the following code :

 DF <- read.table(str_c(chemin,fichier, ".txt"), header = TRUE, sep = '\t', fill = TRUE, dec='.', comment.char = "", quote="")

With col.names argument where i specified every column name of my dataframe.

I spotted a case where a column named "Q5_EVOL" can be reached by only typing :

DF$Q5

All the values of Q5_EVOL are displayed thanks to this code, but as I have to create a column named Q5 (and also another one named Q5_SCORE), when I do a mutate+case_when step, the column created is named "'... <- NULL'" and thanks to tidylog package, I have the following message when executing the column :

new variable '... <- NULL' (double) with 24 unique values and 0% NA

I've also checked with other variables that have prefix, for example SOURCE_TEST and when i execute DF$SOURCE, the values of SOURCE_TEST are displayed.

I've tried to check if it was because of presence of labels and to use other functions of import of txt file such as read.csv, read.csv2, read.delim, but it didn't correct the issue.

I guess that it is something very weird, does anyone here already faced that kind of issue?

Phil
  • 7,287
  • 3
  • 36
  • 66
WalliYo_
  • 173
  • 7
  • This behavior of partial name matching with `$` subsetting is documented in `help("$")` ,and was initially intended for convenience in interactive use. Use `DF[["Q5"]]` to avoid it – Aurèle May 23 '23 at 12:51
  • Does this answer your question? [list members can be accessed with partial name? Is this a feature?](https://stackoverflow.com/questions/48525972/list-members-can-be-accessed-with-partial-name-is-this-a-feature) – Aurèle May 23 '23 at 12:52
  • Thank you for your answer. So, how can I create a variable that has the same prefix as another variable without getting the '... <- NULL' name ? – WalliYo_ May 23 '23 at 12:55
  • 2
    Please include the code with `mutate` and `case_when` that is causing the issue. Ideally, make your example [mininal and reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) so that it can be copy-pasted and run as is to reproduce the issue (no `read.table()` of a local file since that is not relevant to the issue, and is not reproducible) – Aurèle May 23 '23 at 13:00

0 Answers0