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).
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 appendedSuppress 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
Simple Manual Rmarkdown Tables That Look Good in HTML, PDF and Docx
Comparison Between Dplyr::Do/Purrr::Map, What Advantages
Plotting the Average Values for Each Level in Ggplot2
How to Jitter Text to Avoid Overlap in a Ggplot2 Scatterplot
Plot Every Column in a Data Frame as a Histogram on One Page Using Ggplot
Force No Default Selection in Selectinput()
Include Tikz Code in Bookdown Figure Environment
How to Extract Everything Until First Occurrence of Pattern
R Random Forests Variable Importance
To Find Whether a Column Exists in Data Frame or Not
Piecewise Regression with R: Plotting the Segments
Rmarkdown Directing Output File into a Directory
How to Replicate a Ddply Behavior That Uses a Custom Function with Dplyr
Duplicate a Column in Data Frame and Rename It to Another Column Name