1

I am trying to initialise an empty tibble, with column names column types already specified.

code below successfully initialise an empty tibble with names

coltest <- 
  c("exectime", "jancode", "publisher_code", "price_a", "price_b", "title", 
  "date", "star", "purchase", "caption", "reviewer", "comment", "item_info")
dd <- matrix(ncol = 13, nrow = 0) %>% as.data.frame() %>% as_tibble 
colnames(dd) <- coltest

I then try to convert all columns to specific types using read::type_convert() shorthand

dd %>% type_convert(dd, col_types = "tcfnnfDcfcfcc")

This gives error,

Error in substring(col_types, idx, idx) : invalid substring arguments

What am I doing wrong?

taiyodayo
  • 331
  • 4
  • 13
  • 1
    I am afraid it doesn't work in that way. You need something like https://stackoverflow.com/questions/10689055/create-an-empty-data-frame – Ronak Shah Sep 16 '19 at 03:22
  • Thank you for the reply Ronak! It's nice to know "it won't work" from someone knowledgable like you ;) Will try the methods you suggested. I guess tidyverse/readr verbs are not designed to deal with data that is not there yet. – taiyodayo Sep 17 '19 at 00:20
  • 1
    Hi, I appreciate the suggestion this may be a duplicate. However I'd like to note that my question is very specifically about "how to deal with readr::type_convert() error message". Initialising an empty data frame is a solution, but does not directly answer my original question. I'm planning to add a solution here if you could leave my original question I think it will be beneficial to others who may be experiencing the same error message. – taiyodayo Sep 18 '19 at 04:48
  • ok..reopened. You can add an answer now. – Ronak Shah Sep 18 '19 at 04:50

0 Answers0