Product: TIBCO Spotfire®
How to convert data in an Integer column to its Binary equivalent.
In some scenarios, it might be required to convert the integer values (base 10) in a column into Binary (base 2). The steps mentioned in the resolution can be followed to achieve this requirement.
There is no out-of-the-box functionality in Spotfire to convert data in an Integer column to Binary, Hexadecimal or any other base number system. However, the requirement can be achieved by writing a TERR/R Script. The script can then be registered as a Spotfire Expression Function so that it becomes available for use in Spotfire Expression language. The below steps should be followed to create the Expression Function:
- Open Spotfire Analyst > Edit Menu > Data Function Properties, and then click the Expression Functions tab.
- Click New.
- Give a name to the function, e.g. Dec2Bin.
- Set the values: Function type: Conversion function; Return type: String; Catagory: Conversion Function.
- Below is a sample TERR / R script which converts values in Integer column into Binary. Copy and paste the same in the Script box:
#####################################
##Script to convert Decimal to Binary
# Define the conversion function
Dec2Bin <- function(x) if (all(x<2)) x else paste(Dec2Bin(x%/%2), x%%2,
sep="")
# Run the function to produce the output
output <- Dec2Bin(x = input1)
#####################################
Once the expression function is created, it is available for use in the Spotfire expression language(inside the function section). To use these functions, go to Insert Menu >> Calculated column:
You can use these expression functions on your Integer column and it will return the result (Binary) as a calculated column.
Disclaimer: The script code in this article is only a sample to be used as a reference. It is not intended to be used "As Is" in a Production environment. Always test in a Development environment. Make modifications to the script in accordance with your implementation specifications that best suit your business requirements.
NOTE: This expression function is based on a TIBCO Enterprise Runtime for R (TERR) script, so it requires access to a TIBCO Enterprise Runtime for R statistics engine to work. TERR is included in the Professional/Analyst/Desktop Client starting in version 5.0, so there are no additional requirements for this to work in those clients. For this to work in Spotfire Web Player or Automation Services, you need to configure Spotfire to point to a TIBCO Spotfire Statistics Services (TSSS) server instance. This TSSS URL must be configured according to the TIBCO Spotfire Statistics Services Installation and Administration Manual located at the following:
- URL: https://docs.tibco.com/products/tibco-spotfire-statistics-services
- Chapter: Configuring TIBCO Spotfire to use TIBCO Spotfire Statistics Services
Note also that TIBCO Spotfire Statistics Services (TSSS) is a separate product, distinct from Spotfire Server, the Spotfire desktop client, Spotfire Web Player, and Spotfire Automation Services. https://docs.tibco.com/pub/sfire-analyst/7.13.0/doc/html/en-US/TIB_sfire-analyst_UsersGuide/df/df_details_on_expression_functions.htm
http://r.789695.n4.nabble.com/Conversion-to-Binary-base2-td868878.html
Comments
0 comments
Article is closed for comments.