{"id":1895,"date":"2021-01-29T07:38:45","date_gmt":"2021-01-29T07:38:45","guid":{"rendered":"https:\/\/bi.unija.com\/en\/?p=1895"},"modified":"2021-01-29T07:39:08","modified_gmt":"2021-01-29T07:39:08","slug":"r-and-power-bi-debugging","status":"publish","type":"post","link":"https:\/\/bi.unija.com\/en\/r-and-power-bi-debugging\/","title":{"rendered":"R and Power BI &#8211; Debugging"},"content":{"rendered":"<p><em>For Power BI version 2.76.5678.782 (December 2019).<\/em><\/p>\n<p>When debugging scripts we usually follow values of variables. R script editor in Power BI unfortunately doesn&#8217;t provide a variable list, which can make debugging frustrating. We can use a trick proposed by <a href=\"https:\/\/medium.com\/@praveenp\/debugging-power-bi-r-custom-visual-using-r-studio-b1ed18d32fe5\">Praveen N<\/a>: adding a block of code to the script that writes out variables into a file. We can then open the file in RStudio and examine the variables.<\/p>\n<p>We can insert the code in anywhere in R script in Power BI.<\/p>\n<p><strong>########## DEBUG IN R<\/strong><br \/>\n<strong>filename = &#8220;C:\/temp\/Data.Rda&#8221;<\/strong><br \/>\n<strong>if(file.exists(dirname(filename))){<\/strong><br \/>\n<strong>if(Sys.getenv(&#8220;RSTUDIO&#8221;)!=&#8221;&#8221;)<\/strong><br \/>\n<strong>load(file = filename)<\/strong><br \/>\n<strong>else<\/strong><br \/>\n<strong>save(list = ls(all.names = TRUE), file = filename)<\/strong><br \/>\n<strong>}<\/strong><\/p>\n<h1>Example<\/h1>\n<p>Let&#8217;s look at <strong>dataset <\/strong>variable, which is always the name of incoming dataframe. We follow the steps below.<\/p>\n<p>We have a simple table in Power Query. We open R script editor by selecting <strong>Run<\/strong> <strong>R<\/strong> <strong>script<\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"753\" height=\"373\" class=\"wp-image-1896\" src=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2021\/01\/word-image-30.png\" srcset=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2021\/01\/word-image-30.png 753w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2021\/01\/word-image-30-300x149.png 300w\" sizes=\"(max-width: 753px) 100vw, 753px\" \/><\/p>\n<p>We enter the following commands.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"876\" height=\"523\" class=\"wp-image-1897\" src=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2021\/01\/word-image-31.png\" srcset=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2021\/01\/word-image-31.png 876w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2021\/01\/word-image-31-300x179.png 300w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2021\/01\/word-image-31-768x459.png 768w\" sizes=\"(max-width: 876px) 100vw, 876px\" \/><\/p>\n<p>Confirm with <strong>OK<\/strong>.<\/p>\n<p>Open<strong> RStudio<\/strong>.<\/p>\n<p>In <strong>RStudio<\/strong> open file from location <strong>C:\/temp\/Data.Rda<\/strong>.<\/p>\n<p>Confirm with <strong>Yes<\/strong> to load all the variables.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"502\" height=\"156\" class=\"wp-image-1898\" src=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2021\/01\/word-image-32.png\" srcset=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2021\/01\/word-image-32.png 502w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2021\/01\/word-image-32-300x93.png 300w\" sizes=\"(max-width: 502px) 100vw, 502px\" \/><\/p>\n<p>Check the <strong>dataset<\/strong> variable.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"149\" height=\"128\" class=\"wp-image-1899\" src=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2021\/01\/word-image-33.png\" \/><\/p>\n<p>Value of variable is printed out, in our case the original table.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"149\" height=\"128\" class=\"wp-image-1900\" src=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2021\/01\/word-image-34.png\" \/><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For Power BI version 2.76.5678.782 (December 2019). When debugging scripts we usually follow values of variables. R script editor in Power BI unfortunately doesn&#8217;t provide a variable list, which can make debugging frustrating. We can use a trick proposed by<\/p>\n","protected":false},"author":5,"featured_media":1902,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1895","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>R and Power BI - Debugging - Bi Unija<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/bi.unija.com\/en\/r-and-power-bi-debugging\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"R and Power BI - Debugging - Bi Unija\" \/>\n<meta property=\"og:description\" content=\"For Power BI version 2.76.5678.782 (December 2019). When debugging scripts we usually follow values of variables. R script editor in Power BI unfortunately doesn&#8217;t provide a variable list, which can make debugging frustrating. We can use a trick proposed by\" \/>\n<meta property=\"og:url\" content=\"https:\/\/bi.unija.com\/en\/r-and-power-bi-debugging\/\" \/>\n<meta property=\"og:site_name\" content=\"Bi Unija\" \/>\n<meta property=\"article:published_time\" content=\"2021-01-29T07:38:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-01-29T07:39:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2021\/01\/41.png\" \/>\n\t<meta property=\"og:image:width\" content=\"720\" \/>\n\t<meta property=\"og:image:height\" content=\"480\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Branka Trifunovi\u0107\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Branka Trifunovi\u0107\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/bi.unija.com\/en\/r-and-power-bi-debugging\/\",\"url\":\"https:\/\/bi.unija.com\/en\/r-and-power-bi-debugging\/\",\"name\":\"R and Power BI - Debugging - Bi Unija\",\"isPartOf\":{\"@id\":\"https:\/\/bi.unija.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/bi.unija.com\/en\/r-and-power-bi-debugging\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/bi.unija.com\/en\/r-and-power-bi-debugging\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2021\/01\/41.png\",\"datePublished\":\"2021-01-29T07:38:45+00:00\",\"dateModified\":\"2021-01-29T07:39:08+00:00\",\"author\":{\"@id\":\"https:\/\/bi.unija.com\/en\/#\/schema\/person\/3bed36623727c7162e421c4366a54e10\"},\"breadcrumb\":{\"@id\":\"https:\/\/bi.unija.com\/en\/r-and-power-bi-debugging\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/bi.unija.com\/en\/r-and-power-bi-debugging\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/bi.unija.com\/en\/r-and-power-bi-debugging\/#primaryimage\",\"url\":\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2021\/01\/41.png\",\"contentUrl\":\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2021\/01\/41.png\",\"width\":720,\"height\":480},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/bi.unija.com\/en\/r-and-power-bi-debugging\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/bi.unija.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"R and Power BI &#8211; Debugging\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/bi.unija.com\/en\/#website\",\"url\":\"https:\/\/bi.unija.com\/en\/\",\"name\":\"Bi Unija\",\"description\":\"Just another Bi site\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/bi.unija.com\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/bi.unija.com\/en\/#\/schema\/person\/3bed36623727c7162e421c4366a54e10\",\"name\":\"Branka Trifunovi\u0107\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/bi.unija.com\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ec99f651bcc98a163161515ec254b974?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ec99f651bcc98a163161515ec254b974?s=96&d=mm&r=g\",\"caption\":\"Branka Trifunovi\u0107\"},\"url\":\"https:\/\/bi.unija.com\/en\/author\/branka\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"R and Power BI - Debugging - Bi Unija","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/bi.unija.com\/en\/r-and-power-bi-debugging\/","og_locale":"en_US","og_type":"article","og_title":"R and Power BI - Debugging - Bi Unija","og_description":"For Power BI version 2.76.5678.782 (December 2019). When debugging scripts we usually follow values of variables. R script editor in Power BI unfortunately doesn&#8217;t provide a variable list, which can make debugging frustrating. We can use a trick proposed by","og_url":"https:\/\/bi.unija.com\/en\/r-and-power-bi-debugging\/","og_site_name":"Bi Unija","article_published_time":"2021-01-29T07:38:45+00:00","article_modified_time":"2021-01-29T07:39:08+00:00","og_image":[{"width":720,"height":480,"url":"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2021\/01\/41.png","type":"image\/png"}],"author":"Branka Trifunovi\u0107","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Branka Trifunovi\u0107","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/bi.unija.com\/en\/r-and-power-bi-debugging\/","url":"https:\/\/bi.unija.com\/en\/r-and-power-bi-debugging\/","name":"R and Power BI - Debugging - Bi Unija","isPartOf":{"@id":"https:\/\/bi.unija.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/bi.unija.com\/en\/r-and-power-bi-debugging\/#primaryimage"},"image":{"@id":"https:\/\/bi.unija.com\/en\/r-and-power-bi-debugging\/#primaryimage"},"thumbnailUrl":"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2021\/01\/41.png","datePublished":"2021-01-29T07:38:45+00:00","dateModified":"2021-01-29T07:39:08+00:00","author":{"@id":"https:\/\/bi.unija.com\/en\/#\/schema\/person\/3bed36623727c7162e421c4366a54e10"},"breadcrumb":{"@id":"https:\/\/bi.unija.com\/en\/r-and-power-bi-debugging\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/bi.unija.com\/en\/r-and-power-bi-debugging\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/bi.unija.com\/en\/r-and-power-bi-debugging\/#primaryimage","url":"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2021\/01\/41.png","contentUrl":"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2021\/01\/41.png","width":720,"height":480},{"@type":"BreadcrumbList","@id":"https:\/\/bi.unija.com\/en\/r-and-power-bi-debugging\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/bi.unija.com\/en\/"},{"@type":"ListItem","position":2,"name":"R and Power BI &#8211; Debugging"}]},{"@type":"WebSite","@id":"https:\/\/bi.unija.com\/en\/#website","url":"https:\/\/bi.unija.com\/en\/","name":"Bi Unija","description":"Just another Bi site","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/bi.unija.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/bi.unija.com\/en\/#\/schema\/person\/3bed36623727c7162e421c4366a54e10","name":"Branka Trifunovi\u0107","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/bi.unija.com\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/ec99f651bcc98a163161515ec254b974?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ec99f651bcc98a163161515ec254b974?s=96&d=mm&r=g","caption":"Branka Trifunovi\u0107"},"url":"https:\/\/bi.unija.com\/en\/author\/branka\/"}]}},"_links":{"self":[{"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/posts\/1895"}],"collection":[{"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/comments?post=1895"}],"version-history":[{"count":1,"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/posts\/1895\/revisions"}],"predecessor-version":[{"id":1901,"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/posts\/1895\/revisions\/1901"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/media\/1902"}],"wp:attachment":[{"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/media?parent=1895"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/categories?post=1895"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/tags?post=1895"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}