r - `Reduce` instead of `<<-` -


Let's have a function that converts a list into a semi-JSON string:

 < As> code> Properties = Point (in% names) in %% properties) = = gsub ("',' ',' ',' ', places a place around # pairs (' '', '', # 'gsub (' "([^"] +: "," \\ 1: ", # # ToJSON (rapply (properties, as.character))) label = if (is.null (dot [[" label "] ] ") Paste 0 (": ", [Dots [[" Label "]]) ID = if (is (empty ([[" id "]]) NA_character_other point [[" "id"]] query = sprintf ( "% S% s", label, attribute) returns (query)}   

for example:

  as.cypher.list (list (label) AA = A, A = 1, B = "EFU", name = "bar"): # [1] "AA {A: '1', B: 'EFU', name: 'bar'}"   

Now go:

How to change values ​​from in the list query So that each list matches the substrings in the query in the list name? After the replacement is the last desirable result:

  query # [1] "matte (n: aa { A: '1', b: 'foo', name: 'bar'}), (AE: BB {b: '2'}) returns n "  

Sus I:

  add_param = function (nm, val) {Query & lt; & Lt; - gsub (paste0 ("{", nm, "}"), paste 0 ("(", ", nm, as.cypher.list (val),") "), query, fixed = t)} map (add_perm, name (Nodes), nodes) # $ n # [1] "match (n: aa {a: '1', b: 'afu', name: 'bar'}), {ae} returns n" ## $ ae # [1] "Matt (N: AA {A: '1', B: 'AFU', name: 'WESSER'}), (AE: BB: B: '2'}) Return N"   

However & lt; & Lt; - Information about the use of which is quite strange.

How to use reduce () in this case?

The only minor problem here is that when you decrease in the named list You do not have access to names in the ceremony. A way around is to embed the name with just that data. You can make a change such as map (list, name (nodes), nodes) . After this you can have this object once that you can reset it, which has all your necessary information, you can reduce the decrease

  (Function (q, n) {nm & lt; -n [[1]] val & lt; - n [[2]] gsub (paste0 ("{", nm, "}"), paste 0 ("( You also want to consider extraction / replacement with ", nm, as.cypher.list (val),") (A: A) {A: '1', B: 'Foo' 'Code: regmatches' Can be considered '', name: 'bar'}), (AE: bb {b: '2'}) returns n "  

() . One such strategy is

  tnodes & lt; -mapply (function (nm, val) paste0 ("(", nm, as.cypher.list (val), ")"), name (nodes), nodes query & lt ; - "MATCH {n}, {ae} RETURN n" m & lt; - gregexpr ("\\ {[^}] + \\}", query) regmatches (query, m) & lt; - lapley (Query, M), Function (X) {Name & lt; - substr (x, 2, nchar (x) -1) tnodes [name]} Query # [1] "Match (N: AA Basically we first (A: '1', b: 'afu', name: 'bar'}), (AE: BB {b: '2'}) returns n "  

transformed nodes Cache values, then look at all '{xx}' tokens and replace them with related values When husband.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -