issue importing .txt file

I'm trying to read a .txt file into rstudio. The file consists of 13 columns and 71 rows. The first column is an ID with characters and numbers (e.g., subject001) and the remaining columns are all numbers (with the exception of some "NaNs" indicating that the participant did not provide a response).

When I try to import the file using this command:
df <- readtext("file.txt")
it creates a table with one row and 2 columns. The first column is called "doc_id" and is just the name of the file. The second column is called "text" and includes all the column headers but not any data (that I can see).

Any help would be much appreciated. Thank you!

Referred here from support.rstudio.com

Can you provide a sample of the txt file?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

Sure, here's a link to a sample file: https://drive.google.com/file/d/1UJAZ8M_919-rrgKTjN_irOkLt_HVmR6h/view?usp=sharing

use the readr package

library(readr)

url <- "https://drive.google.com/u/0/uc?id=1UJAZ8M_919-rrgKTjN_irOkLt_HVmR6h&export=download"

df <- read_table2(url)

df
#> # A tibble: 70 x 13
#>    subjid  var1 var2  var3   var4   var5   var6  var7 var8   var9 var10 var11
#>    <chr>  <dbl> <chr> <chr> <dbl>  <dbl>  <dbl> <dbl> <chr> <dbl> <dbl> <dbl>
#>  1 subj_…     1 xmwd  eh        1  0.183  0.5   0.622 9$        0 0.850 0.826
#>  2 subj_…     1 xmwd  eh        2  5.73  -2     0.119 9$        1 0.883 0.854
#>  3 subj_…     1 xmwd  eh        3  9.80  -0.5   0.378 9$        1 1.27  1.24 
#>  4 subj_…     1 xmwd  eh        4 14.4   -1     0.269 6#        0 1.08  1.05 
#>  5 subj_…     1 xmwd  eh        5 19.9    1     0.731 6#        1 0.917 0.895
#>  6 subj_…     1 xmwd  eh        6 26.0   -2     0.119 9$        1 0.833 0.808
#>  7 subj_…     1 xmwd  eh        7 29.6   -1     0.269 9$        1 0.950 0.932
#>  8 subj_…     1 xmwd  eh        8 34.1    0.125 0.531 9$        0 0.667 0.633
#>  9 subj_…     1 xmwd  eh        9 38.2   -0.25  0.438 9$        1 0.750 0.719
#> 10 subj_…     1 xmwd  eh       10 43.7   -0.125 0.469 6#        0 0.733 0.716
#> # … with 60 more rows, and 1 more variable: var12 <dbl>

Created on 2020-05-08 by the reprex package (v0.3.0)