trinker / qdap

Quantitative Discourse Analysis Package: Bridging the gap between qualitative data and quantitative analysis
http://cran.us.r-project.org/web/packages/qdap/index.html
175 stars 44 forks source link

Save polarity data frame to excel file #125

Closed lorenaromero86 closed 11 years ago

lorenaromero86 commented 11 years ago

Hi, I used your package to run some polarity analysis in tweets, but when trying to export the data to excel I am getting errors, can you please help me to know what I am doing wrong? below the code I am trying to run (in windows 7)

Tks.

library(XLConnect)
library("qdap")
library(xlsx)

excel.file <- file.path("C:/Documents/Data/SMALLER_SET.xlsx")
elements <- readWorksheetFromFile(excel.file, sheet=1)

poldat <- with(elements, polarity(text,n))
out1 <- merge(elements, poldat$all, by.x=qcv(n, text), by.y=qcv(n, text.var))

setwd("C:/Documents/Data")
write.xlsx(x = out1, file = "out1.xls", sheetName = "out1", row.names = FALSE)

After this what I get is:

Error in .jcall(cell, "V", "setCellValue", value) : 
  method setCellValue with signature ([Ljava/lang/String;)V not found
In addition: Warning message:
In if (is.na(value)) { :
  the condition has length > 1 and only the first element will be used
trinker commented 11 years ago

I'm not sure about the exact cause of your error as I don't have your data but I do know that the neg.words and pos.words are actually a list of vectors stored in a data.frame object. Writing to csv/xlsx won't work with some sort of adjustment (i.e., collapsing to a single character string.). I added two non exported functions to the development version of qdap as seen below:

library(qdap)
poldat <- with(DATA, polarity(state, person))
out1 <- merge(DATA, poldat$all, by.x=qcv(person, state), by.y=qcv(person, text.var))

paste3 <- function(x, sep = ", "){
    sapply(x, paste, collapse = sep)
}

condense <- function(dataframe, ...) {
    whichlist <- sapply(dataframe, is.list)
    dataframe[, whichlist] <- sapply(dataframe[, whichlist], paste3, ...)
    dataframe
}

library(xlsx)
## Notice the use of condense
write.xlsx(x = condense(out1), file = "out1.xls", sheetName = "out1", row.names = FALSE)

If you download the dev. vserion of qdap you paste3 and condense are nonexported functions you could access this way:

write.xlsx(x = qdap:::condense(out1), file = "out1.xls", sheetName = "out1", row.names = FALSE)
trinker commented 11 years ago

I decided to add condense as an exported function. You can use:

write.xlsx(x = condense(out1), file = "out1.xls", sheetName = "out1", row.names = FALSE)

after installing the dev version.

lorenaromero86 commented 11 years ago

Hi, thanks a lot, it solved my problem! as it would be said in spanish: eres un sol! (you are a sunshine!).

trinker commented 11 years ago

Glad I could help.

You did well with the GitHub report and as you can see it emails you and I both of notifications. Let's learn a little more about GitHub. If your problem has been solved you can close it. Try it out.

TAwosanya commented 7 years ago

Trinker, you are the best, this post helped me a great deal!