FAQ Database Discussion Community


R convert character to dataframe column name and then replace values in a column

r,eval,assign
I was able to get content of the column pointed by character variable b. But i want to make column emp 0. How could i do that? emp=c(1,2,30) abc=data.frame(emp) b="emp" #below line gives content of column emp eval(parse(text=paste("abc$", b, sep = ""))) #how can i replace each value in column...

Why can you use eval() with the function repr(y) inside and not str(y)?

python,string,eval,repr
Here is some code that I've found and would like for someone to explain. If I assign a string to the variable y, evaluate it with the eval function and assign the content to the variable y2, the interpreter returns true. >>> y = 'a string' >>> y2 = eval(repr(y))...

<%#Eval %> in asp.net to move page

html,asp.net,http,hyperlink,eval
Like other 'List' page, I'm making a <a> tag on td, and 3buttons 'Go up','Go down','Go list'. I succeed after click this link, go another page. <a href="NoticeDetail.aspx?seq=<%#Eval("Seq") %>"><%#Eval("Title")%></a> Now, the problem is here. To make Go up/down pages, I guess put the number +1 on the link to calculate...

Javascript Eval overwriting variable

javascript,eval
Don't understand why the code below is overwriting my var arr. Any help appreciated. var arr = [1,2,3] var string = "function swap(arr) { var newarr = arr; var temp = arr[0]; newarr[0] = arr[arr.length-1]; newarr[arr.length-1] = temp; return newarr }" var test = eval("[" + string + "]")[0]; test(arr);...

Format both an expression and its result without eval

common-lisp,eval
I am trying to format an arbitrary expression, say (+ 2 3), and at the same time, its result, 5. I have the following: (defun expr-and-result (expr) (format t "~a returns ~a~%" expr (eval expr))) CL-USER> (expr-and-result '(+ 2 3)) (+ 2 3) returns 5 Though it's a simple matter...

How to convert a statement in a string into a format that can be evaluated (Ruby)

ruby,string,eval
I am writing a quiz program where I need to store boolean statements as strings in an array and output them to the terminal as part of a question. I then want to evaluate the contents of these strings and return the value so that I can test whether I...

How does str(list) work?

python,string,list,eval,python-internals
Why does str(list) returns how we see list on the console? How does str(list) work? (any reference to the CPython code for str(list))? >>> x = ['abc', 'def', 'ghi'] >>> str(x) "['abc', 'def', 'ghi']" To get the original list back from the str(list) I have to: >>> from ast import...

Emacsclient crashes when evaluating window functions

emacs,window,eval
To not bore anyone here with specifics, whenever I evaluate an expression similar to this one: emacsclient -t -e '(set-buffer *scratch*)' the client will flash up on the terminal and crash. This seems to be happening with all window-changing functions. Is the client not supposed to work like that? Running...

How to De-Stringify Stringified JavaScript?

javascript,parsing,eval,stringify
How to 'de-stringify' JavaScript code that has been stringified? JSON.parse does not seem to work. We want to store JavaScript code in the database and then retrieve it and then eval it. Here's the code in the database: //# sourceURL=journal.js function onBlur(e) { var drAmount = script.getGridRowFieldValue('debitamount', e.rowuid) var crAmount...

Using eval to print an array value

php,arrays,eval
$cars = array ( array("Volvo",22,18), array("BMW",15,13), array("Saab",5,2), array("Land Rover",17,15) ); $key = '[1][0]'; $str = '$cars'.$key; echo $str."\n"; eval($str); Output: $cars[1][0] PHP Parse error: syntax error, unexpected end of file in ... : eval()'d code on line 1 I'm expecting it to print the value, i.e BMW...

Php: json to constants

php,eval,constants
I have a Json that contains a few contants I'd like to auto-define. It works fine with simple "key": "val" statements, but I can't make it work for eval staments: $cat test.php <?php function objDefinition($obj) { foreach ($obj as $key => $val) { $val = $val; \define($key, $val); } }...

Parse a string expression

python,regex,parsing,expression,eval
I need to parse a string which contains an expression. The language is proprietary and I am not sure I know the complete syntax but essentially an example expression looks like this: "some_name+(some_other_name * 4 * different_name)+ 'h40028" There are various names i've illustrated as some_name etc above which I...

How to evaluate custom javascript expression with the context in strict mode?

javascript,properties,scope,this,eval
Update I've come up with a concise solution to this problem, that behaves similar to node's vm module. var VM = function(o) { eval((function() { var src = ''; for (var prop in o) { if (o.hasOwnProperty(prop)) { src += 'var ' + prop + '=o[\'' + prop + '\'];';...

Evaluate expression in R data.table

r,eval,data.table
I have the following data.table: > dt = data.table(expr = c("a + b", "a - b", "a * b", "a / b"), a = c(1,2,3,4), b = c(5,6,7,8)) > dt expr a b 1: a + b 1 5 2: a - b 2 6 3: a * b 3...

Eval Inside Of Funtion Results In Error, While Outside It Does Not

python,eval
I wrote a small python script that takes in descriptions of simple impedance networks and calculates the effective impedance. The code is pastebined here. The code, as is, runs correctly, but if you sub in the commented out lines that are below them, which simply moves the eval to the...

undefined local variable or method after eval when not declared before

ruby,eval
In Ruby 2.1.2 :068 > a=1 => 1 2.1.2 :069 > eval("a=4") => 4 2.1.2 :070 > a => 4 2.1.2 :071 > eval("b=4") => 4 2.1.2 :072 > b NameError: undefined local variable or method `b' for main:Object So,the question is why the variable 'b' will be 'undefined local...

PHP eval not executing properly

php,eval,heredoc
Could someone point out what I'm mistaking here? :) <?php $q = $_GET[q]; $acuman = <<<PARSE input: (contains: "hello"){ output: "hello"; } PARSE; $acuman = str_replace("input: (contains: ", 'if(strpos(', $acuman); $acuman = str_replace("){", ', $q) !== false) {', $acuman); $acuman = str_replace("output: ", '$output = ', $acuman); eval($acuman); ?> I'm...

Is this eval() in python safe?

python,eval,code-injection
consider this code: from re import sub input = request.POST['input'] sub_pattern = {'1':"sub('pattern1','txt1',input)", '2':"sub('pattern2','txt2',input)", } eval(sub_pattern['1']) is there code-injection in this code? can you provide POC on this code injection?...

is there a way to avoid eval() to accomplish dynamic dispatch of a function specified in a list in python

python,eval
I have a list as defined here: header_fields = [ ['delim',0,4,'strip()'], ['qual',4,5,None], ['NLS_CODE',6,25,'strip()'], ['source_system_id',26,45,'strip()'], ['extract_name',46,65,'strip()'], ['extract_serial_number',66,85,'strip()'], ['file_counter',86,88,"lstrip('0')"], ['total_file_count',89,91,'strip()'], ['extract_run_date_time',92,126,'strip()'], ['from_date',127,161,'strip()'], ['thru_date',162,196,'strip()'], ['number_of_rows',197,216,'strip()'], ['data_recons1',217,246,'strip()'],...

Foreach loop unable to find object

r,foreach,parallel-processing,eval
I am trying to use foreach with the parallel backend to speed up computation (of cross validation of an {AUCRF} random forest for feature selection, if this does matter). In the process of doing so i need to get a subset of a vector. The name of the vector can...

Remove quotation marks from an object

ruby,string,eval
I want to call User.first, but I get it like "User.first". How can I strip the quotation marks so I can call User? Using a regex like this: gsub!(/\A"|"\Z/, "") returns nil instead of the expression.

Is there a better alternative to eval() for my function checking algorithm

javascript,jquery,eval,jquery-mask
I have the following code below designed to check that a function exists at anytime. This code does not have any errors currently. I'm using this because my javascript files load in arbitrary orders and is necessary for my project its done that way. Since my javascript files are separated...

How to concatenate period in eval ASP.net

html,asp.net,eval
I have a ASP.net Label whose Text is defined as follows Text='<%# Eval("Price", "{0:&pound;0.00 ex. VAT}") %>' This displays the label as follows ignoring the 'period' between ex and VAT. How do i handle this? £99.99 ex VAT...

clojure quoting inside let

clojure,macros,eval
Quoting (both syntax and non-syntax) seems to fail to detect vars inside a let statement: (let [foo 1] (eval `(print foo))) This will generate an error or use whatever prior value bound was bound to foo in (def foo bar). Is there a way to make the syntax quote use...

Save a dictionary key as a variable

python,dictionary,multidimensional-array,key,eval
I'm working on a small framework and I've found a place where it would be beneficial to save a dictionary key as variable. The problem I have is that the dictionary may have any number of layers, so it's not just a case of storing the final key. For example...

How to use this javascript code with eval or in a iim file?

javascript,eval,imacros
I want to use this code with eval or in a iim file without using js file.I tried for using it into eval but didn't work.Or is there any other way that can allow this code into iim file directly? please help me! do { do { iimPlay("CODE:ondialog pos=1 button=ok...

using Eval of ASP Listview as an inline CSS value

asp.net,listview,warnings,eval
my code is : <asp:ListView ID="lst1" runat="server"> <ItemTemplate> <div style="width:<%#Eval("Rating")%>%"> </div> </ItemTemplate> </asp:ListView> It works great, but in VisualStudio editor it's considered as invalid. Is there any way to make it valid? I know that I can create the whole ' style="width:xxx%" ' in the Eval but I'm looking for...

Can an inserted