Define all functions in one .R file, call them from another .R file. How, if possible?

You can call source(“abc.R”) followed by source(“xyz.R”) (assuming that both these files are in your current working directory. If abc.R is: fooABC <- function(x) { k <- x+1 return(k) } and xyz.R is: fooXYZ <- function(x) { k <- fooABC(x)+1 return(k) } then this will work: > source(“abc.R”) > source(“xyz.R”) > fooXYZ(3) [1] 5 > … Read more

Adding code to a javascript function programmatically

If someFunction is globally available, then you can cache the function, create your own, and have yours call it. So if this is the original… someFunction = function() { alert(“done”); } You’d do this… someFunction = (function() { var cached_function = someFunction; return function() { // your code var result = cached_function.apply(this, arguments); // use … Read more

How to report an error from a SQL Server user-defined function

You can use CAST to throw meaningful error: create function dbo.throwError() returns nvarchar(max) as begin return cast(‘Error happened here.’ as int); end Then Sql Server will show some help information: Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value ‘Error happened here.’ to data type int.

Overriding a JavaScript function while referencing the original

You could do something like this: var a = (function() { var original_a = a; if (condition) { return function() { new_code(); original_a(); } } else { return function() { original_a(); other_new_code(); } } })(); Declaring original_a inside an anonymous function keeps it from cluttering the global namespace, but it’s available in the inner functions. … Read more

How to strip all non-alphabetic characters from string in SQL Server?

Try this function: Create Function [dbo].[RemoveNonAlphaCharacters](@Temp VarChar(1000)) Returns VarChar(1000) AS Begin Declare @KeepValues as varchar(50) Set @KeepValues=”%[^a-z]%” While PatIndex(@KeepValues, @Temp) > 0 Set @Temp = Stuff(@Temp, PatIndex(@KeepValues, @Temp), 1, ”) Return @Temp End Call it like this: Select dbo.RemoveNonAlphaCharacters(‘abc1234def5678ghi90jkl’) Once you understand the code, you should see that it is relatively simple to change it … Read more

Multi-statement Table Valued Function vs Inline Table Valued Function

In researching Matt’s comment, I have revised my original statement. He is correct, there will be a difference in performance between an inline table valued function (ITVF) and a multi-statement table valued function (MSTVF) even if they both simply execute a SELECT statement. SQL Server will treat an ITVF somewhat like a VIEW in that … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)