An error I can't understand. “Promise already under evaluation…” [duplicate]

血红的双手。 提交于 2019-12-01 13:25:40

Someone can correct me on this, but I think that you are passing Primus and Name as objects to the function and it is looking in the .GlobalEnv for those objects and is not finding them, therefore your function is failing to carry out most of your instructions (and is returning nothing). I have edited your function a bit.

Instead try this...

 namezz <- function( pattern = " ", data , column= "Name" ){
   library(stringr)
   strings <- data[ , column ] ##data$column is a character vector
   found = str_detect( strings , pattern )
   yez = rownames( data[ which( found==TRUE ) , ] )
   hhh = as.numeric( yez ) + 1
   return( hhh )
 }

Then you must use the function like so:

namezz( "Primus" , data = data ) #In this case the default for column is "Name" as you want

The problem with passing data = data is explained very nicely here. An excerpt from that post (where they refer to testparams you would refer to data)...

"One of the most important things to know about the evaluation of arguments to a function is that supplied arguments and default arguments are treated differently. The supplied arguments to a function are evaluated in the evaluation frame of the calling function. The default arguments to a function are evaluated in the evaluation frame of the function."

the parameter testparams, when no matching argument is passed, is given the default value which is the value of the variable testparams looked-up not in the environment where foo is defined, and not in the environment where foo is called, but rather in the local environment created when the function is called and where parameters are mapped to values -- and in this environment, testparams is a parameter, which is already being under evaluation, hence the recursive lookup error.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!