2

I try to save some R-dataframes into .xlsx-files using the write.xlsx function of the xlsx package like this

write.xlsx(tab,file="test",sheetName="testsheet",col.names=TRUE,row.names=FALSE,append=FALSE)

whereas the object tab is a data frame, as prooved here

> class(tab)
[1] "data.frame"

When I run the code I get the following error message

>  write.xlsx(tab,file="test.xlsx",sheetName="testsheet",col.names=TRUE,row.names=FALSE,append=FALSE)
Fehler in .jcall("RJavaTools", "Z", "hasField", .jcast(x, "java/lang/Object"),  : 
  RcallMethod: cannot determine object class

and I have no particular idea what the problem could be.

PS: I'm running R 2.14.1 in the StatET 2.0 plugin in Eclipse 3.7 on a 64bit machine.

7
  • Are you using RTerm or rj in Eclipse? Commented Mar 26, 2012 at 11:25
  • rj! Can this be the Problem? Commented Mar 26, 2012 at 11:31
  • 1
    Yes, it could. Try your code in RTerm. (I can't remember the details how I made xlsx work, but it's worth a try.) Commented Mar 26, 2012 at 11:33
  • Maybe you're right! It works when I run the code with TinnR... curiouser and curiouser... or do you even know why? I'd be very interested! Commented Mar 26, 2012 at 11:44
  • 1
    I have never tried to figure out why, but several things don't work properly in rj. This includes all use of RCOM as well as printing of the return value of system(). I use rj by default because I like the way it deals with help, but if things don't work, I try it in RTerm. One day I'll have some spare time and I'll take it up with the author. Commented Mar 26, 2012 at 11:46

3 Answers 3

2

When you work in Eclipse, you can start R using either rj - a Java terminal, or RTerm - the native R terminal.

If you are using the rj terminal and something doesn't work, try the same thing with RTerm.

I have never tried to figure out why, but a few things don't work properly in rj. This includes all use of RCOM as well as printing of the return value of system().

I use rj by default because I like the way it deals with help (amongst other benefits).
But if things don't work, I try it in RTerm. One day I'll have some spare time and I'll take it up with the author.


PS. I want to stress that I absolutely love StatET in Eclipse. These oddities or rj are very minor inconveniences in the grand scheme of things.

Sign up to request clarification or add additional context in comments.

1 Comment

I <3 StatET/Eclipse too (noticed it again when doint the stuff in TinnR -> doesn't even know code folding...)
2

From my experience these kind of errors are produced when the standard rj package is installed instead of the one supplied bij the StatET developer. Check the installation guide here: http://www.walware.de/goto/statet

If you would happen to be using Debian or Ubuntu, you can also use the repository from OpenAnalytics to install StatET and the correct rj packages in one go.

http://deb.openanalytics.eu/howto.html

Comments

0

I had same problem. Two codes work with my problem:

FIRST) Convert vector to dataframe:

library(xlsx)
data <- data.frame(c(1,2,3))
write.xlsx(data, file = "C:/Users/Name/Downloads/data.xlsx")

SECOND) Use another library:

`# Using openxlsx package library(openxlsx)
dataD1 <- data.frame(c(1,2,3))
write.xlsx(dataD1, "C:/Users/Name/Downloads/dataD1.xlsx")

I hope you have solved your problem.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.