Forum Discussion

ACraig08's avatar
ACraig08
Helper III
2 years ago
Solved

R script not showing result when using an if statement

I am using the R visual to provide my outputs from my t-test. I used the following code to print out the results (it might look different because I had to use Notepad++ to change the variable names for privacy reasons):

It prints out the results just fine except that the results of the if statement don't show up. 

The statements run fine when I test them in R. Any help is greatly appriciated.

  • I figured it out! because I was using cat() it wasn't storing the results in my variable! I changed it to use paste() and it worked just fine!

3 Replies

  • I am surprised it works at all. Usually they will not allow you to use any renderer apart from matplotlib.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi ACraig08 ,
    Based on your description and the provided code screenshot, please check the syntax of the if statement and the code block within it for any errors and make sure that the condition in the if statement is met. If the condition is not met, the code in the if block will not be executed. If you want to output the result, make sure there is a print or return statement in the if block to output the result. In the context of the R visual object in Power BI, a data frame should be created that will be returned as output. You can also run the same script in an interactive R session outside of Power BI (e.g. RStudio) to see if it produces the expected output. Finally, make sure that your R language package is ready to run in power bi
    Learn which R packages are supported - Power BI | Microsoft Learn
    Use R in Power Query Editor - Power BI | Microsoft Learn

    Best regards

    Albert He

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly



  • I figured it out! because I was using cat() it wasn't storing the results in my variable! I changed it to use paste() and it worked just fine!