R 错误:names() 应用于非向量 [英] R Error: names() applied to a non-vector

查看:76
本文介绍了R 错误:names() 应用于非向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段代码,只有在我第一次运行时才会产生错误.奇怪的是,如果我第二次运行它,我没有错误(疯狂定义?).此外,错误并不总是出现在相同的位置,我的意思是如果我添加几行注释,错误消息将在注释之后而不是在特定指令之后打印.

I have a chunk of code which produces an error only the first time I run it. Strangely if I run it a second time I get no error (craziness definition?). Also the error does not show up always at the same position, I mean that if I add a few lines of comments the error message is printed after the comments and not after a specific instruction.

我无法提供可重现的示例,因为我不知道错误的确切来源.错误如下:

I cannot provide a reproducible example because I do not know where exactly the error comes from. The error is the following:

Error in names(frame)[names(frame) == "x"] <- name : 
  names() applied to a non-vector

我应该指定在我的代码中我没有 - 至少明确地 - names() 函数.

I should specify that in my code I don't have -at least explicitly- a names() function.

推荐答案

这是一个棘手的错误.我能够找到原因,似乎 R 有一个与缓存的函数同名的对象.如果使用诸如 RStudio 之类的 IDE,这很可能是 View(df) 的选项卡.除非选项卡关闭,否则即使运行没有代码的函数也会给你这个错误.同样,如果选项卡没有关闭,甚至不删除所有对象或进行垃圾收集都可以解决它.一旦标签关闭,错误就会消失.

This is a tricky error. I was able to track down the reason and it seems to be that R has an object of the same name as the function cached. This is most likely if using an IDE such as RStudio a tab for View(df). Unless the tab is closed even running the function without code will give you this error. Likewise, if the tab is not closed not even removing all objects or doing a garbage collection will solve it. Once the tab is closed the error will be gone.

这篇关于R 错误:names() 应用于非向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆