Question: I have a txt file like this:
[["seller\_id","product\_id","buyer\_id","sale\_date","quantity","price"],[7,11,49,"2019-01-21",5,3330],[13,32,6,"2019-02-10",9,1089],[50,47,4,"2019-01-06",1,1343],[1,22,2,"2019-03-03",9,7677]]

I would like to read it by R as a table like this:

| seller\_id | product\_id | buyer\_id | sale\_date | quantity | price |
| --- | --- | --- | --- | --- | --- |
| 7 | 11 | 49 | 2019-01-21 | 5 | 3330 |
| 13 | 32 | 6 | 2019-02-10 | 9 | 1089 |
| 50 | 47 | 4 | 2019-01-06 | 1 | 1343 |
| 1 | 22 | 2 | 2019-03-03 | 9 | 7677 |

How to write the correct R code? Thanks very much for your time.

Answer: 
An easier option is `fromJSON`

```
library(jsonlite)
library(janitor)
fromJSON(txt = "file1.txt") %>% 
    as_tibble %>% 
    row_to_names(row_number = 1) %>%
    type.convert(as.is = TRUE)

```

-output

```
# A tibble: 4 x 6
#  seller_id product_id buyer_id sale_date  quantity price
#      <int>      <int>    <int> <chr>         <int> <int>
#1         7         11       49 2019-01-21        5  3330
#2        13         32        6 2019-02-10        9  1089
#3        50         47        4 2019-01-06        1  1343
#4         1         22        2 2019-03-03        9  7677

```
Some base R options using:

---

* `gsub` + `read.table`

```
read.table(
  text = gsub('"|\\[|\\]', "", gsub("\\],", "\n", s)),
  sep = ",",
  header = TRUE
)

```

---

* `gsub` + `read.csv`

```
read.csv(text = gsub('"|\\[|\\]', "", gsub("\\],", "\n", s)))

```

which gives

```
  seller_id product_id buyer_id  sale_date quantity price
1         7         11       49 2019-01-21        5  3330
2        13         32        6 2019-02-10        9  1089
3        50         47        4 2019-01-06        1  1343
4         1         22        2 2019-03-03        9  7677

```

**Data**

```
s <- '[["seller_id","product_id","buyer_id","sale_date","quantity","price"],[7,11,49,"2019-01-21",5,3330],[13,32,6,"2019-02-10",9,1089],[50,47,4,"2019-01-06",1,1343],[1,22,2,"2019-03-03",9,7677]]'

```