Is there string formatting function in Kusto? - azure-data-explorer

I am struggling to find that in the list of scalar functions. Is there something more convenient that strcat() for string formatting in Kusto?

Related

Boost Date_time How to construct given a string and a format

I have a string which is a date specified using a specific format string.
I would like to create a Boost Date_Time from it.
IO can of course use the format string to create a facet which I can then use in a stringstream, but that seems so convoluted. Is there a better way?

Fast way to determine if variable is a function?

To determine if a variable is a function, I use the following method
function isFunction(variable)
return type(variable) == "function"
end
To my knowledge, this is a string comparison. As I've understood it, string comparisons are relatively slow and I fear this function might be a bottleneck in my code. Is there a less costly way to determine if a variable is a function?
I'm hoping there's a function which returns an integer that indicates the type of the variable instead. Or I can ask my question another way: How does type(var) determine the type of a variable? Surely, each variable can't hold a string representing its type so I'm guessing there is some backend-stuff in lua that looks up the string "function" when invoking type(var).
String comparisons in Lua are really fast because most strings are interned.
Internally, every Lua value contains a tag identifying its type. It is this tag that type uses.

How to evaluate a variable and print as a string/character in R?

I've tried finding this on SO without any luck:
How do I convert a closure object into a string in R?
I have a list of functions, like this:
functions = c(function(x) 2*x, function(x) sin(x*pi), function(x))
And, I iterate over them like for (func in functions){..., and I'd like to be able print the function expression as part of my plotting.
I've tried:
toString(eval(func))
as.character(eval(func))
What gives?
Related links:
How to evaluate a variable as an expression for axis label in R?
Evaluate expression given as a string
There seems to be no easy way to accomplish this. Here is the best way I found:
as.character(parse(text=as.list(func)))
For a more general solution, you can capture the output, as #chinsoon said.

R - Please explain this code and how to make a function that outputs like it?

I am new to R and mostly working with old code written by someone else. And I am trying to create my own R functions.
I found some of the following code used for eigenvalue decomposition.
eigenMatrix = eigen(myMatrix)[[2]]
eigenVals = eigen(myMatrix)[[1]]
Here there is single function that can output 2 different data structures, being, a vector and a matrix depending of the value in the brackets.
When I search of functions with multiple outputs, they usually use lists to output multiple variables at once which does not work, possibly because of different types.
I don't understand why there are two setts of brackets and how the underlying function would work.
The posted code takes the eigen function, which returns a list with 2 values.
Then the [[]] are use to extract the first and second items from the list.
The [[]] is needed to return the underlying structure, and is better explained here: How to Correctly Use Lists in R?
Also, since the eigen function is run twice the code in the question is inefficient.
resultList = eigen(myMatrix)
eigenMatrix = resultList[[2]]
eigenVals = resultList[[1]]
This code is better since eigen is run only once and saves the result of the function as a list and then reads the values from the list.
For the function itself can be coaded as any function with multiple outputs such as here: https://stat.ethz.ch/pipermail/r-help/2007-March/126851.html or here: How to assign from a function with multiple outputs?
The list values can hold any structure and [[]] can be used to return the underlying structure of each value.

Return R object given its name

Given the name of an R object (as a string), how can I return the object with that name?
(The context in which this comes up is that I am running the function findGlobals, which returns a vector objects as a strings. I would like to then iterate through the list and test to make sure each name refers to a function using is.function. If you know of a solution to this specific problem without the more general question above, that would also be appreciated.)
get() is what you're looking for. And by "iterate" I assume you mean using an apply variant, e.g.
sapply(ls(), FUN = function(x) is.function(get(x)))

Resources