This site uses different types of cookies, including analytics and functional cookies (its own and from other sites). To change your cookie settings or find out more, click here. If you continue browsing our website, you accept these cookies.
I have been doing some file manipulation via Alteryx and when it became apparent that there wasn't an easy way to create multiple directories if they don't already exist, and to then copy the appropriate files to both an archive destination and the production destination. I wanted to reach out to inquire about a method to do this via the R Tool and not through the use of a .bat file. The reason .bat files via the Run Command won't work is due to security constraints within my environment. Here is what I am attempting to do:
Each Month I receive 2 files from a vendor with a unique naming convention that I can parse through via Alteryx to create the date range of the data within the file and the name of my archive folder.
For these two files, each has a different destination directory, which is an archive folder.
Also, for those same 2 files, I need to rename them to two different names and then MOVE them to a production folder.
I have used RStudio to run the exact code that I need for this to work and it runs smoothly. When I attempt to do this in Alteryx itself, I get errors or I don't get an error and it seems to work but truly doesn't. I read my 2 rows into the R tool as a list and have attempted to use lapply(x, dir.create), which works in RStudio yet not in Alteryx (R Tool). I have also done this not using lapply and via just a dir.create(unlist(x)) and a few other variations that work in RStudio yet not in Alteryx despite accounting for the fact that my input from Alteryx is handled as a list. Any thoughts on how to handle this?
I understand the objection to the .bat file not working. But I was wondering if a command solution might still be possible. If you use the Run Command and pass it an argument to create the directory, will that work? I am attaching a sample run command workflow.
As a Read Result, I have a dummy file that literally contains the word dummy on line 1 and line 2. With just this one tool on the workflow I can create the subdirectory. If this is a macro, you can update the directory as part of the configuration.
Please give it a try.
Alteryx ACE & Top Community Contributor
Chaos reigns within. Repent, reflect and reboot. Order shall return. Please Subscribe to my youTube channel.
Thank you for the insight! Fortunately, the functions that I have been using with R are base components of R. The lapply, file.copy, unlist, and dir.create are all a part of the base installation. These are the only arguments I am attempting to utilize for this exercise. Can you think of any reason as to why I would get the hangups that I have had attempting to use base packages?
I think the Command line solution might be a feasible method. I am getting no security errors, which works well for me. I will have to spend some time refreshing myself on command line and check the forums for a good way to pass dynamic parameters from my Alteryx flow into it correctly before being able to call this one finished. I suppose this is a good opportunity to create a macro as well. As I re-engineer this to accommodate the Run Tool, I will reach back out if I get any issues on my end.
It may not be through R, but if it works cohesively, I will roll with it.
Thanks for the additional thoughts on this. I ended up taking a blended approach using the thoughts throughout this thread. I created a process which systematically built an "If not exist" statement for all of the files within the source folder and fed those into a similar macro to yours, albeit a smidge simpler. With the code being generated via formula tools, I am able to do a check to ensure that I am not creating the same directories with the "if not exist" statements, as well as via the macro, I am able to use command line (cmd.exe, not a batch file) to process each statement systematically and quickly.
Overall, it works like a charm and I don't get errors if it the folder doesn't exist. I wanted to do this via R, but this seems easier to execute on and share with others.
Thanks again for the insight and assistance to each and every one of you!