Applying a macro to all files under a folder - recursion

I am using gvim 7.4 on Windows.
I have a macro recorded that I want to apply on specific files (for example, *.sql) under a parent directory. If I open the file and press #q, the macro works perfectly fine.
Is there a way I can recursively search for all .sql files and apply the macro? I can do this manually by opening the individual files but I wanted to see if I could use a "search and apply macro" method.
Thanks!

there are bufdo and argdo commands. At least you can trigger your macro in normal command.
something like:
:bufdo exe 'norm! #q' |w
give it a try.
Note, this will save the file after the macro is played.

Related

Can I run output of Python code/text file in Julia?

I wrote a python script that generates a tree and outputs some variable creation and function calls in Julia syntax to a text file (I am testing the correctness of some Julia tree algorithms in phylogenetics).
I was wondering if there is a way to "run" the text file in a Julia Jupyter notebook?
It gets tedious to manually copy the file and run it as I am generating many files.
You can run include("treealgos.jl") in a Jupyter cell, to run the entire file there. It's equivalent to copy-pasting the file contents to that cell, and all the variables and functions defined in the file become available in the notebook after that.
Note that this is very different from using or importing a module, which require a module name and come with extra features like namespacing and exports. An include in contrast is a more basic and simpler feature, similar to a #include in C language, just bringing the code that was included into wherever the include statement happens to be.

How to create a file in Julia?

Is there a quick and simple way I can create a new file (whether it be a txt or .jl file) from the REPL or in Julia script? I would usually do something like use the touch command from the terminal (even though that is designed to update the timestamp of when the file was last edited).
It looks like I can use the open function in "create" mode but I prefer to not use that syntax.
As it turns out, there is actually a touch function in Julia:
julia> touch("test.txt")
"test.txt"
which similar to the terminal command, is designed to allow you to update the timestamp of when the file was last modified, but if the file does not exist, the touch command will create it for you. You can read more about the touch command in the Julia docs.

How do I copy a file in Julia?

I am trying to copy a file using Julia functions with the hope of manipulating the file and then use that copied version for various tasks in the Julia programming language. Can someone provide some example code of copying a file in Julia?
I guess I could do use read then write but it seems like I would be reinventing the wheel.
Is there a standard library function for this?
Inspired by this question.
Just use the built in function cp(src, dst).
Copy the file, link, or directory from src to dst. force=true will first remove an existing dst.
Afterwards you can open the file and manipulate it. Of course you could also open both source an destination files simultaneously and copy and manipulate it line by line.

Saving .R script File Using Script

I am using R Studio and I want to save my script (i.e., the upper left panel). However, the only ways that I can find to do it are by either clicking the blue floppy disk icon to save or using the drop down menu File > Save > name.R
Is there any way besides using these shortcuts to save the script to a .R file or is the shortcut the only way?
Thanks.
You can use rstudioapi::documentSave() to save the currently open script file to disk.
From the source documentation, one can see that it can be used in conjunction with the id returned with getActiveDocumentContext()$id to make sure the document saved is the one running the script.
For your intended use, try:
rstudioapi::documentSave(rstudioapi::getActiveDocumentContext()$id)
For future reference, here is the reference manual of rstudioapi:
https://cran.rstudio.com/web/packages/rstudioapi/rstudioapi.pdf
I'm not yet allowed to comment, but this refers to the comment above that this does not work with .rmd files:
rstudioapi::documentSave(rstudioapi::getActiveDocumentContext()$id)
I tried and in Rstudio Version 1.2.5042 it does seem to work.
Every new tab in R(created by ctrl+shift+n) can be independently saved by using ctrl+s in the respective tab. If you intend to rename the file though, you may do it as you would rename any file in windows(goto the file location and single click on the filename). Hope my answer was of some help!

read .sas source code on osx without installing sas?

Plain and simple: is there a way to read (not run) .sas files on osx in order to rewrite old SAS programs in another language, e.g. R? Note I do not refer to reading sas data files – I know there are several ways, I am just interested in reading old SAS code.
.sas files containing SAS code should just be a text file. You can use any text editor that you like to open and modify these files. Since the system probably doesn't have .sas files associated with any particular program you can either use the "Open with" option when "right-clicking" on the file or you could open the editor first and then open the file from within the editor.
TextEdit will work. Another editor that I like is Komodo Edit.

Resources