Unimplemented Type List When Trying to Write.Table

Unimplemented type list when trying to write.table

As mentioned in the comments, you should be able to do something like this (untested) to get "flatten" your list into a character vector:

output$Title <- vapply(output$Title, paste, collapse = ", ", character(1L))

As also mentioned, if you wanted to try the unlist approach, you could "expand" each row by the individual values in output$Title, something like this:

x <- vapply(output$Title, length, 1L)          ## How many items per list element
output <- output[rep(rownames(output), x), ] ## Expand the data frame
output$Title <- unlist(output$Title, use.names = FALSE) ## Replace with raw values

Error in writing dataframe in csv

It has to do with writing a matrix (with multiple dimensions) to a df in which multiple cols have no dimensions (vector). I found this solution to work (see Outputting a Dataframe in R to a .csv)

# First coerce the data.frame to all-character
df_Place2 = data.frame(lapply(df_Place, as.character), stringsAsFactors=FALSE)

# write file
write.csv(df_place2,"tx.csv")

How to output a list in R

The following solution seems to have worked. Thanks, @Ian Campbell

# Row bind
df = do.call(rbind, my_list)

# Take transpose
df2 = t(df)

write.csv(df2, "test.csv", row.names = F)

Outputting a Dataframe in R to a .csv

One of your columns is of type list, so the data.frame is no longer 2-dimensional and can't be exported to a 2d csv-file.

If you still want to store the list in the resulting output, you might transform it to JSON first. So it becomes an column of type "character" which can be easily exported as one column to csv.

Appending List Elements in write.table

It appears to be baked-in, depending solely on the col.names and append arguments and no easy way to squelch it there.

In general it's just a warning, but since it was elevated to Error status, that suggests you've set options(warn = 2) or higher. It's not a factor for these resolutions (which result in no warning being emitted and therefore no escalation to an error).

  1. Suppress it and all other warnings (for good or bad):

    write.table(data.frame(a=1,b=2), "quux.csv", append=T, sep="\t", quote=F, row.names=F)
    # Error in write.table(data.frame(a = 1, b = 2), "quux.csv", append = T, :
    # (converted from warning) appending column names to file

    suppressWarnings(write.table(data.frame(a=1,b=2), "quux.csv", append=T, sep="\t", quote=F, row.names=F))
    ### nothing emitted, file appended
  2. Suppress just that warning, allowing others (since suppressing all can hide other issues):

    withCallingHandlers(
    write.table(data.frame(a=1,b=2), "quux.csv", append=T, sep="\t", quote=F, row.names=F),
    warning = function(w) {
    if (grepl("appending column names to file", conditionMessage(w))) {
    invokeRestart("muffleWarning")
    }
    })
    ### nothing emitted, file appended

    withCallingHandlers(
    write.table(data.frame(a=1,b=2), "quux.csv", append=T, sep="\t", quote=F, row.names=F),
    warning = function(w) {
    if (grepl("something else", conditionMessage(w))) {
    invokeRestart("muffleWarning")
    }
    })
    # Error in write.table(data.frame(a = 1, b = 2), "quux.csv", append = T, :
    # (converted from warning) appending column names to file


Related Topics



Leave a reply



Submit