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

在SparkR中尝试创建简单表格时遇到错误。问题源于R加载库的方式导致使用了SparkR::table而非R原生table函数。解决方案是在函数前添加base::以确保使用正确的table函数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Create table function in Spark in R not working

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

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值