j解决sparkr中使用某些r的原生函数 发生错误Error: class(objId) == "jobj" is not TRUE的问题

Create table function in Spark in R not working

2700008550 gravatar image
João_Andre  (3) 询问的问题 | 2016年12月10日 06:03BLUEMIXRSPARK

Hello, I'm trying to create a simple table in Bluemix Spark (R) but getting a error I can't understand or find useful reference about. Has anyone seen something similar? Any suggestions, please?

  1. one <- rep(1,2)
  2. two <- rep(2,2)
  3. my_table <- table(one,two)
  4. my_table
  5. Error: class(objId) == "jobj" is not TRUE
  6. Traceback:
  7. 1. table(one, two)
  8. 2. callJMethod(sqlContext, "table", tableName)
  9. 3. stopifnot(class(objId) == "jobj")
  10. 4. stop(sprintf(ngettext(length(r), "%s is not TRUE", "%s are not all TRUE"),
  11. . ch), call. = FALSE, domain = NA)
 
   0
 

4 个答案

 · 添加您的答案
310000ESE9 gravatar image
 

由 Sven Hafeneger (176回答 

I think this happens due to how in R the libraries are loaded. In this case the last library loaded is "SparkR", which has a function exported with the name "table". The SparkR::table function is used, if you not fully qualify the function. That explains why in the traceback "callJMethod(sqlContext, "table", tableName)" is stated.

On workaround is to qualify the function. This worked for me for R - Spark 1.6

  1. one <- rep(1,2)
  2. two <- rep(2,2)
  3. my_table <- base::table(one,two)
  4. my_table

However, it is interesting that it works for R - Spark 2.0.

 
   1   分享
 
110000HD3V gravatar image
 

由 RolandWeber (56回答 

Does your code snippet work in other R environments? It looks very much different from the table examples that I could find. Are you sure that "rep" in your example generates a "factor"? Maybe you have to call the "factor" function explicitly, as shown in the first link?

http://www.cyclismo.org/tutorial/R/types.html#tables

https://www.stat.berkeley.edu/classes/s133/factors.html

https://www.r-bloggers.com/r-function-of-the-day-table/

 
   0   分享
 
2700008550 gravatar image
 

由 João_Andre (3回答 

Hello, yes, it used to work. I got it working now after changing kernel to "R with Spark 2.0".

Thanks for your help and the links provided.

João

 
   0   分享
 
2700008550 gravatar image
 

由 João_Andre (3回答 

@Sven, thanks for your clear explanation.

 
   0   分享
 
 
总结:
在sparkR中使用R的原生函数报错时
在函数前加base:::
例如z为r中的data.frame
对其在sparkr中使用table函数则需如下形式

base:::table(z)

原文地址:https://www.cnblogs.com/awishfullyway/p/6632734.html