<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: R Code running differently in Alteryx in Alteryx Designer Desktop Discussions</title>
    <link>https://community.alteryx.com/t5/Alteryx-Designer-Desktop-Discussions/R-Code-running-differently-in-Alteryx/m-p/232689#M51144</link>
    <description>A wild guess is to assess the data types coming in: I like v_string or v_wstring of sufficient max length, trimmed of excess whitespace. Perhaps sone sanity checks within R too, to ensure it's not the data</description>
    <pubDate>Thu, 23 Aug 2018 05:07:03 GMT</pubDate>
    <dc:creator>JohnJPS</dc:creator>
    <dc:date>2018-08-23T05:07:03Z</dc:date>
    <item>
      <title>R Code running differently in Alteryx</title>
      <link>https://community.alteryx.com/t5/Alteryx-Designer-Desktop-Discussions/R-Code-running-differently-in-Alteryx/m-p/231283#M51115</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am attempting to turn an R script that I have into an Alteryx flow. Unfortunately, I can't share the data behind this, but I changed it a bit so I can share the following R code. My issue is that this code doesn't do the correct things in Alteryx. It works perfectly fine in R Studio, however.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: I think &lt;STRONG&gt;stringr&amp;nbsp;&lt;/STRONG&gt;and&amp;nbsp;&lt;STRONG&gt;Hmisc&lt;/STRONG&gt; are the only packages I use in this section of code, although I have about seven packages read in altogether for this script.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Going into this step of the code, a sample of the column headers look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[1]&amp;nbsp;"ABCD.ns1:awardID.ns1:awardContractID.ns1:companyID"&lt;/P&gt;&lt;P&gt;[2] "ABCD.ns1:awardID.ns1:awardContractID.ns1:modNumber"&lt;/P&gt;&lt;P&gt;[3] "ABCD.ns1:typeID.ns1:referenceID.ns1:companyID"&lt;BR /&gt;[4] "ABCD.ns1:typeID.ns1:referenceID.ns1:companyCity"&lt;BR /&gt;[5] "ABCD.ns1:purchaserInformation.ns1:shippingCompanyID"&lt;BR /&gt;[6] "ABCD.ns1:purchaserInformation.ns1:&lt;SPAN&gt;shippingCompanyID&lt;/SPAN&gt;.departmentID"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After running this code in R Studio, the columns look like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[1]&amp;nbsp;"AwardContractID_companyID(ABCD)"&lt;/P&gt;&lt;P&gt;[2]&amp;nbsp;"AwardContractID_modNumber(ABCD)"&lt;/P&gt;&lt;P&gt;[3]&amp;nbsp;"ReferenceID_companyID(ABCD)"&lt;/P&gt;&lt;P&gt;[4]&amp;nbsp;&lt;SPAN&gt;"ReferenceID_companyCity(ABCD)"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;[5]&amp;nbsp;"ShippingCompanyID(ABCD)"&lt;/P&gt;&lt;P&gt;[6]&amp;nbsp;&lt;SPAN&gt;"ShippingCompanyID.departmentID(ABCD)"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;However, after running the same code in the R tool in Alteryx, the columns look like:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[1]&amp;nbsp;"ABCD.Ns1.Awardid.Ns1:Awardcontractid.Ns1.Companyid(ABCD)"&lt;/P&gt;&lt;P&gt;[2] &lt;SPAN&gt;"ABCD.Ns1.Awardid.Ns1:Awardcontractid.Ns1.M&lt;/SPAN&gt;odnumber(ABCD)"&lt;/P&gt;&lt;P&gt;[3] "ABCD.Ns1.Typeid.Ns1.Referenceid.Ns1.Companyid(ABCD)"&lt;BR /&gt;[4] &lt;SPAN&gt;"ABCD.Ns1.Typeid.Ns1.Referenceid.Ns1.Companycity(ABCD)"&lt;/SPAN&gt;&lt;BR /&gt;[5] "ABCD.Ns1.Purchaserinformation.Ns1.Shippingcompanyid(ABCD)"&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;[6] &lt;SPAN&gt;"ABCD.Ns1.Purchaserinformation.Ns1.Shippingcompanyid.Departmentid(ABCD)"&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There must be some reason why Alteryx isn't running this correctly, but I can't figure it out. The rest of my R script seems to work fine. It is only this section that is causing me problems.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;i = 0
ind = c()
name_list &amp;lt;- c()
for (name in colnames(Main_Data)) {
  i = i + 1
  x &amp;lt;- str_detect(name, "^ABCD")
  if (x == TRUE) {
    a &amp;lt;- str_detect(name, "awardContractID")
    b &amp;lt;- str_detect(name, "referenceID")
    if (a == TRUE) {
      ind &amp;lt;- c(ind,i)
      y &amp;lt;- unlist(strsplit(name, split = ":", fixed = TRUE))
      z &amp;lt;- y[length(y)]
      name2 &amp;lt;- paste0("awardContractID_",z,"(ABCD)")
      name_list &amp;lt;- c(name_list, name2)
    } else if (b == TRUE) {
      ind &amp;lt;- c(ind,i)
      y &amp;lt;- unlist(strsplit(name, split = ":", fixed = TRUE))
      z &amp;lt;- y[length(y)]
      name2 &amp;lt;- paste0("referenceID_",z,"(ABCD)")
      name_list &amp;lt;- c(name_list, name2)
    } else {
      ind &amp;lt;- c(ind,i)
      y &amp;lt;- unlist(strsplit(name, split = ":", fixed = TRUE))
      z &amp;lt;- y[length(y)]
      name2 &amp;lt;- paste0(z,"(ABCD)")
      name_list &amp;lt;- c(name_list, name2)
    }
  }
}
i &amp;lt;- 1
for (j in ind) {
  colnames(Main_Data)[j] &amp;lt;- name_list[i]
  i = i + 1
}&lt;BR /&gt;&lt;BR /&gt;colnames(Main_Data) &amp;lt;- capitalize(colnames(Main_Data))&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated. Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 20:54:40 GMT</pubDate>
      <guid>https://community.alteryx.com/t5/Alteryx-Designer-Desktop-Discussions/R-Code-running-differently-in-Alteryx/m-p/231283#M51115</guid>
      <dc:creator>rnewby</dc:creator>
      <dc:date>2018-08-22T20:54:40Z</dc:date>
    </item>
    <item>
      <title>Re: R Code running differently in Alteryx</title>
      <link>https://community.alteryx.com/t5/Alteryx-Designer-Desktop-Discussions/R-Code-running-differently-in-Alteryx/m-p/232689#M51144</link>
      <description>A wild guess is to assess the data types coming in: I like v_string or v_wstring of sufficient max length, trimmed of excess whitespace. Perhaps sone sanity checks within R too, to ensure it's not the data</description>
      <pubDate>Thu, 23 Aug 2018 05:07:03 GMT</pubDate>
      <guid>https://community.alteryx.com/t5/Alteryx-Designer-Desktop-Discussions/R-Code-running-differently-in-Alteryx/m-p/232689#M51144</guid>
      <dc:creator>JohnJPS</dc:creator>
      <dc:date>2018-08-23T05:07:03Z</dc:date>
    </item>
    <item>
      <title>Re: R Code running differently in Alteryx</title>
      <link>https://community.alteryx.com/t5/Alteryx-Designer-Desktop-Discussions/R-Code-running-differently-in-Alteryx/m-p/237324#M51200</link>
      <description>&lt;P&gt;It looks like everything going in is v_string and everything coming out of the R code is v_wstring. I'm not sure if that is normal behavior, as I'm not too familiar with Alteryx data types, but it seems OK. The data check in&amp;nbsp;R seems fine. I just can't figure out why the code doesn't do the exact same thing in both places.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Aug 2018 15:24:02 GMT</pubDate>
      <guid>https://community.alteryx.com/t5/Alteryx-Designer-Desktop-Discussions/R-Code-running-differently-in-Alteryx/m-p/237324#M51200</guid>
      <dc:creator>rnewby</dc:creator>
      <dc:date>2018-08-23T15:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: R Code running differently in Alteryx</title>
      <link>https://community.alteryx.com/t5/Alteryx-Designer-Desktop-Discussions/R-Code-running-differently-in-Alteryx/m-p/237523#M51205</link>
      <description>&lt;P&gt;Since these are columns names of pretty intense complexity, could you try simply reading in your dataset in R, then outputting it again, literally doing nothing to it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You may find that the column names are altered as part of the hand-off from Alteryx to R.&amp;nbsp; Doing this may help to understand what's happening there and allow you to work around it somehow.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS, you could also do a Field Info to get the column names, then use normal Alteryx tools to develop the new names, then a Dynamic Rename to swap the new names back in. :-)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope that helps!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Aug 2018 15:37:16 GMT</pubDate>
      <guid>https://community.alteryx.com/t5/Alteryx-Designer-Desktop-Discussions/R-Code-running-differently-in-Alteryx/m-p/237523#M51205</guid>
      <dc:creator>JohnJPS</dc:creator>
      <dc:date>2018-08-23T15:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: R Code running differently in Alteryx</title>
      <link>https://community.alteryx.com/t5/Alteryx-Designer-Desktop-Discussions/R-Code-running-differently-in-Alteryx/m-p/238340#M51219</link>
      <description>&lt;P&gt;Good catch! I tried outputting the data with no changes, and apparently, Alteryx-to-R replaces all colons with periods. So when my code tries to split on the colon, it is not splitting on anything whatsoever.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Out of curiosity, what&amp;nbsp;would you recommend to do complex renaming?&amp;nbsp;RegEx is the first thing that comes to mind, but that is brutal to use for all the odd text changes I need.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Aug 2018 16:33:57 GMT</pubDate>
      <guid>https://community.alteryx.com/t5/Alteryx-Designer-Desktop-Discussions/R-Code-running-differently-in-Alteryx/m-p/238340#M51219</guid>
      <dc:creator>rnewby</dc:creator>
      <dc:date>2018-08-23T16:33:57Z</dc:date>
    </item>
    <item>
      <title>Re: R Code running differently in Alteryx</title>
      <link>https://community.alteryx.com/t5/Alteryx-Designer-Desktop-Discussions/R-Code-running-differently-in-Alteryx/m-p/238452#M51222</link>
      <description>&lt;P&gt;In Alteryx, I would probably do the Field Info / Formulas / Dynamic Rename approach for modifying complex names. The Formula tool has some pretty good string manipulation functions, and also has RegEx functions (similar to the RegEx tool. The nice thing about doing it this way is the intermediate view that Alteryx always gives you at each tool in the flow... (don't have to code in print statements in R to spit out intermediate data or whatever have you.)&lt;/P&gt;</description>
      <pubDate>Thu, 23 Aug 2018 16:41:09 GMT</pubDate>
      <guid>https://community.alteryx.com/t5/Alteryx-Designer-Desktop-Discussions/R-Code-running-differently-in-Alteryx/m-p/238452#M51222</guid>
      <dc:creator>JohnJPS</dc:creator>
      <dc:date>2018-08-23T16:41:09Z</dc:date>
    </item>
    <item>
      <title>Re: R Code running differently in Alteryx</title>
      <link>https://community.alteryx.com/t5/Alteryx-Designer-Desktop-Discussions/R-Code-running-differently-in-Alteryx/m-p/258840#M51461</link>
      <description>&lt;P&gt;I've also run into this issue before and my solution was to read in the column names as a second data source. The original data will go to the R tool as input #1, and I also pass it through a Field Info tool which will give the column names as input #2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.PNG" style="width: 400px;"&gt;&lt;img src="https://community.alteryx.com/t5/image/serverpage/image-id/41610iC954C0935B5264FE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="1.PNG" alt="1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(The Select tool is there to deselect all the other Field Info which&amp;nbsp;aren't needed, but you don't necessarily have to do this). Then in the R tool you can read in the names from the Field Info side and then assign them to the column names of your original data, like so:&lt;/P&gt;&lt;PRE&gt;x &amp;lt;- read.Alteryx("#1", mode="data.frame")
xnames &amp;lt;- read.Alteryx("#2", mode="data.frame")
colnames(x) &amp;lt;- xnames$Name&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Aug 2018 20:14:13 GMT</pubDate>
      <guid>https://community.alteryx.com/t5/Alteryx-Designer-Desktop-Discussions/R-Code-running-differently-in-Alteryx/m-p/258840#M51461</guid>
      <dc:creator>DavidxL</dc:creator>
      <dc:date>2018-08-27T20:14:13Z</dc:date>
    </item>
    <item>
      <title>Re: R Code running differently in Alteryx</title>
      <link>https://community.alteryx.com/t5/Alteryx-Designer-Desktop-Discussions/R-Code-running-differently-in-Alteryx/m-p/271215#M51584</link>
      <description>&lt;P&gt;Thank you. This worked perfectly.&lt;/P&gt;&lt;P&gt;It's strange -- I wonder why reading the column names in separately doesn't affect them in the same way as reading the entire data frame. An Alteryx mystery...&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Aug 2018 01:05:27 GMT</pubDate>
      <guid>https://community.alteryx.com/t5/Alteryx-Designer-Desktop-Discussions/R-Code-running-differently-in-Alteryx/m-p/271215#M51584</guid>
      <dc:creator>rnewby</dc:creator>
      <dc:date>2018-08-29T01:05:27Z</dc:date>
    </item>
    <item>
      <title>Re: R Code running differently in Alteryx</title>
      <link>https://community.alteryx.com/t5/Alteryx-Designer-Desktop-Discussions/R-Code-running-differently-in-Alteryx/m-p/272794#M51644</link>
      <description>&lt;P&gt;I suspect this is more of an R issue, because similarly if you try to read in a CSV directly in R (i.e. in RStudio using read.csv() ) it will also try to convert the column names into "valid" names. See the R help for ?make.names for more info. I think this is because in R you can attach and call columns of a dataframe as "bare name" R variables, so it's generally good practice that the column names of your data frame are actually legal R variable names.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Reading in the column names separately is passing them in as data rather than column names, and after they're read in you can assign them to the data frame even if it can cause potential issues.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Aug 2018 12:13:14 GMT</pubDate>
      <guid>https://community.alteryx.com/t5/Alteryx-Designer-Desktop-Discussions/R-Code-running-differently-in-Alteryx/m-p/272794#M51644</guid>
      <dc:creator>DavidxL</dc:creator>
      <dc:date>2018-08-29T12:13:14Z</dc:date>
    </item>
    <item>
      <title>Re: R Code running differently in Alteryx</title>
      <link>https://community.alteryx.com/t5/Alteryx-Designer-Desktop-Discussions/R-Code-running-differently-in-Alteryx/m-p/288684#M51803</link>
      <description>&lt;P&gt;Interesting! I had no idea that R changed the data columns to fit with any particular standard. I always use the &lt;STRONG&gt;readr&amp;nbsp;&lt;/STRONG&gt;package to bring in CSVs to R, so I never noticed this. A made up a few lines of test data with "-" and ":" in the column names. And then I read the first in using the &lt;STRONG&gt;default&lt;/STRONG&gt; &lt;EM&gt;read.csv()&lt;/EM&gt; and the second using the &lt;STRONG&gt;readr&amp;nbsp;&lt;/STRONG&gt;&lt;EM&gt;read_csv():&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="TestColNames.png" style="width: 400px;"&gt;&lt;img src="https://community.alteryx.com/t5/image/serverpage/image-id/41917i16929733F916F549/image-size/medium?v=v2&amp;amp;px=400" role="button" title="TestColNames.png" alt="TestColNames.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Apologies for blaming Alteryx for this behavior!&lt;/P&gt;&lt;P&gt;Are you aware of any alternative way of reading data into Alteryx besides&amp;nbsp;&lt;STRONG&gt;read.Alteryx("#1", mode="data.frame")&lt;/STRONG&gt;? That's the only way I've seen data read into the R Tool.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 18:27:09 GMT</pubDate>
      <guid>https://community.alteryx.com/t5/Alteryx-Designer-Desktop-Discussions/R-Code-running-differently-in-Alteryx/m-p/288684#M51803</guid>
      <dc:creator>rnewby</dc:creator>
      <dc:date>2018-08-30T18:27:09Z</dc:date>
    </item>
    <item>
      <title>Re: R Code running differently in Alteryx</title>
      <link>https://community.alteryx.com/t5/Alteryx-Designer-Desktop-Discussions/R-Code-running-differently-in-Alteryx/m-p/288920#M51807</link>
      <description>&lt;P&gt;I'm not aware of any alternatives provided by Alteryx (not counting the other modes available to the&lt;STRONG&gt; read.Alteryx&lt;/STRONG&gt; function). It seems to use a package called AlteryxRDataX but no information that package is shared, unlike some of the other Alteryx packages which they've hosted on their Github. If you're looking for more you might have to resort to calling R using the Cmd tool.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 18:48:00 GMT</pubDate>
      <guid>https://community.alteryx.com/t5/Alteryx-Designer-Desktop-Discussions/R-Code-running-differently-in-Alteryx/m-p/288920#M51807</guid>
      <dc:creator>DavidxL</dc:creator>
      <dc:date>2018-08-30T18:48:00Z</dc:date>
    </item>
    <item>
      <title>Re: R Code running differently in Alteryx</title>
      <link>https://community.alteryx.com/t5/Alteryx-Designer-Desktop-Discussions/R-Code-running-differently-in-Alteryx/m-p/289766#M51824</link>
      <description>&lt;P&gt;If desired, you could use a Block Until Done tool; in the first output, write to a .csv file; then in the 2nd have your R tool and user readr there (and a delete at the end to remove the file once finished).&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 20:01:09 GMT</pubDate>
      <guid>https://community.alteryx.com/t5/Alteryx-Designer-Desktop-Discussions/R-Code-running-differently-in-Alteryx/m-p/289766#M51824</guid>
      <dc:creator>JohnJPS</dc:creator>
      <dc:date>2018-08-30T20:01:09Z</dc:date>
    </item>
  </channel>
</rss>

