Inputting a file in R without setwd() - json

I'm trying to input a text file into R using grep and using setwd() (I can use other methods, I'm not sure what, I'm only starting to learn R).
I'm writing a json template for a third-party server that runs a docker image as an env but currently there is a bug that can't change the working directory. Is there another way to get this file?

If you're trying to do something like this:
setwd('/tmp')
read.csv('hello.csv')
You can do without setwd:
read.csv('/tmp/hello.csv')

Related

Getting Minizinc output as .txt from IDE

Imagine I ran a .mzn with .dzn and got an output in IDE as follows:
Supplier01,100,100,100,100,100,100,100,100,100,100,100,100
Supplier02,200,200,200,200,200,200,200,200,200,200,200,200
Supplier03,40,49,359,834,1067,1377,334,516,761,1001,1251,1583
Supplier04,500,500,500,500,500,500,500,500,500,500,500,500
Supplier05,161,200,200,200,200,200,200,200,200,200,200,200
Supplier06,500,500,500,500,500,500,500,500,500,500,500,500
----------
==========
Is there any way that I can generate this output in a .txt or .csv file in a preferred location on my computer? I know that we can perform this in command prompt, but is there any way we can do using the IDE it self?
The MiniZinc IDE currently does not include functionality to export solutions for other applications.
The current expectation is that if you want to integrate MiniZinc with other applications that you would use something like MiniZinc Python, iMiniZinc, or the command line tools, to facilitate the connection. In your case using MiniZinc Python or iMiniZinc might be a good solution since Python can generate csv files using the csv module. If you want to see and interact with the solution as well as outputting the csv file, then iMiniZinc can provide the right tooling in Jupyter Notebook to do both.
If you are very happy with the MiniZinc IDE and you want to continue using it, then the other option would to just minimize the inconvenience. Your output statement already provides the solution in csv style. So the only remaining part is making the file. The MiniZinc IDE can open .csv files. So my suggestion would in this case be to create an empty .csv file, open it in the IDE. Once you get the solution from your instance in the output window, then you copy directly into the file.

How to automate getting a CSV file from this website?

I've never worked with web pages before and I'd like to know how best to automate the following through programming/scripting:
go to http://financials.morningstar.com/ratios/r.html?t=GMCR&region=USA&culture=en_US
invoke the 'Export to CSV' button near the top right
save this file into local directory
parse file
Part 4 doesn't need to use the same language as for 1-3 but ideally I would like to do everything in one shot using one language.
I noticed that if I hover my mouse over the button it says: javascript:exportKeyStat2CSV(); Is this a java function I could call somehow?
Any suggestions are appreciated.
It's a JavaScript function, which is not Java!
At first glance, this may seem like you need to execute Javascript to get it done, but if you look at the source of the document, you can see the function is simply implemented like this:
function exportKeyStat2CSV(){
var orderby = SRT_keyStuts.getOrderFromCookie("order");
var urlstr = "//financials.morningstar.com/ajax/exportKR2CSV.html?&callback=?&t=XNAS:GMCR&region=usa&culture=en-US&cur=&order="+orderby;
document.location = urlstr;
}
So, it builds a url, which is completely fixed, except the order by part, which is taken from a cookie. Then it simply navigates to that url by setting document.location. A small test shows you even get a csv file if you leave the order by part empty, so probably, you can just download the CSV from the base url that is in the code.
Downloading can be done using various tools, for instance WGet for Windows. See SuperUser for more possibilities. Anyway, 'step 1 to 3' is actually just a single command.
After that, you just need to parse the file. Parsing CSV files can be done using batch, and there are several examples available. I won't get into details, since you didn't provide any in your question.
PS. I'd check their terms of use before you actually implement this.
The button directs me to this link:
http://financials.morningstar.com/ajax/exportKR2CSV.html?&callback=?&t=XNAS:GMCR&region=usa&culture=en-US&cur=&order=asc
You could use the Python 3 module urllib and fetch the file, save it using the os or shutil modules, then parse it using one of the many CSV parsing modules, or by making your own.

Ant + JSON: How to read JSON from a file, modify it then write it back to the file

I need to do this using Ant in an Eclipse project:
Read a JSON file (that is located inside my Eclipse project), parse it, so I can make a change on one of the attributes in there, and finally write the resulting JSON back to the same file.
Is this possible? I have tried using an approach of using with JavaScript, but I can't even reach the file without specifying an absolute path (that I don't want to do, I'd prefer this to be relative to the Ant script.)
Thanks in advance

How to store response of rails app to filesystem

I would like to generate a bunch of static pages with my rails app, which then will be stored to the filesystem in order to be part of a build step in a yeoman webapp.
The filetypes would be JSON and HMTL.
Therefore I would like to know what would be the best solution for this problem. Fetching the site with Nokogiri or something similar, transform it to string and put it into a file. Or maybe write a rake task, which starts curl which then puts it into a file.
Or is there something build-in which can handle this type of problem?
Update:
I guess I have to make my goal clearer: I would like to build a website generator, which can export webpages and json to the local file system. In order to get fast response times and to use my existing build process I would like to generate those files and not serve them via rails.
Not sure what you're trying to do, but you might consider something like middleman. It's meant to generate static files, but you can still do ruby/rails like magic, etc.
http://middlemanapp.com/

Use text from CSV in Imagemagick

I have a CSV with information relating to images such as name etc. , is there a way that I can use the CSV file information to push to imagemagick (via PHP on windows) to add to the images?
Sure, check out http://php.net/manual/en/function.fgetcsv.php to get the CSV information into the script, then I'd assume you are using the PHP ImageMagick extension, so just run the commands against the given image, or read the image in from some variable from the file. If you are not using the extension in PHP, you could try running it through the exec PHP method: http://php.net/manual/en/function.exec.php