How do I run an R script from within RStudio's built-in R console? - open-source

I'm assuming it's like Python's import statement, but I'd like a quick answer, since I'm in the middle of an introduction class right now.
This was the closest I got, but it didn't seem to match the question, as it shows how to run an R Script from the system CLI, not the blue RStudio > prompt:
Run an R-script from command line and store results in subdirectory

Short Answer using source() function
Once you download, install, and open the RStudio, you'll see a part in the lower left with blue greater than symbols >.
In the part of RStudio's GUI with the blue >, enter the following
> setwd('/folder/where/the/file/is/')
> source('file_name')`
...output, if any, appears below...
Example:
Let's assume I have a file at /home/myusername/prj/r/learn_r/insurance_data.r that I want to run.
I would start up RStudio, and enter the following in the little window it has labeled Console:
Annoyingly long answer with screenshots using source() function
Well, it turned out to be much simpler than I expected to run this from RStudio's built-in console. I was surprised that this had not already been asked about RStudio, before. If it has, I guess I'll have a burned question.
Anyway, a little trial and error showed me how to do this:
Yay, output has appeared below.
Make sure to set your working directory, first.
I did this as follows from inside RStudio 1.0.143 on my Ubuntu 16.04 LTS environment:
setwd("~/proj/r/learn_r")
Next, you can enter help(source), you can search for the syntax of the source() function, and you can just type it in to the RStudio console for a prompt:

If you want to run a specific line from the R script, put the cursor somewhere in the line and press command+enter (on other pc I think is ctrl+enter). If you want to run the whole script or some parts, select the part and command+enter.

Related

Octave pop up message

I am running Octave 4.4.1 on MacOs Catalina 10.15.7. For some weeks I have been having this message poping up when a code is running: "
It seems that [name of script] has been modified by another application. DO you want to reload it?
I click Yes each time it pops up, but when the code is running, it just keeps coming back, and sometimes Octave becomes unresponsive although the script has finished running
All I could find on the internet were either some old posts with answers about outdated Octave versions, or very complicated stuff that I would not be able to implement.
Any one knows why this happens, and what to do about it?
thanks a lot
This message is exclusive to the GUI version of Octave, and it comes up if you have a file open for editing in the Octave GUI Editor window, and the file's contents change due to a process unrelated to the Octave Editor.
E.g. you may also be editing the file on an external text editor at the same time? Or your script may be copying / generating a new file under the same name as a file that you've got open in the editor, effectively overwriting the now-out-of-date version that's still being displayed in the Octave Editor?
Octave gives you this warning to prevent you from 'saving' in your editor, and therefore undoing any changes that had been made by the external process in the meantime.

View SQL code for job in SQL Server Management Studio

I want to view the SQL code that is executed for a particular job in SQL Server Management Studio.
Specifically, I have a screen that looks like this:
If I double click it I get a screen that looks like this:
That is not really helpful. I want to see the actual code that is running and possibly modify it.
I am a long time developer but new to Windows so please give an answer that uses terminology that I can see on the screen.
[EDIT] If I click the edit button on the first screen I get the same screen as if I double click it. There is a DTSRun command and some jibberish which is not anything I would expect to edit.
[EDIT] I followed these instructions to decode the encrypted command line:
https://blogs.technet.microsoft.com/vipulshah/2007/03/12/how-to-identify-which-dts-package-is-being-called-by-scheduled-job/
Then I could see the command line looks like this:
DTSRun /S "192.168.2.1" /U "sa" /P "changeme" /N "Delete AppErrors"
I then searched the entire computer for a filename that contained AppErrors in the name. I did not find one.
So I am getting closer, but how do I find what that is executing?
There is no SQL code in this job/task, because the task type is "Operating system (CmdExec)", i.e. this is not a SQL query, but starting of Windows executable file. There will be SQL code for step type "Transact-SQL script (T-SQL)":
What you see in you job step, is execution of SSIS package, which is encrypted. For more information about DTSRun command, take a look at this article - SQL Server DTS command line utility.
I almost solved my problem like this:
A.
I followed the instructions here to decode the encrypted command line:
https://blogs.technet.microsoft.com/vipulshah/2007/03/12/how-to-identify-which-dts-package-is-being-called-by-scheduled-job/
Which amounted to:
Copy the DTSRUN line (everything including the DTSRUN)
Open a Windows Command Line window
Paste the DTSRUN line into the CMD window.
To the end of the line, add /!X /!C
/!X = do not execute /!C = copy results onto Windows Clipboard
Run the command
Open Notepad
Click Edit>Paste
that will paste the actual command into Notepad and it will show the name of the package.
B.
I observed that the command line looked like this:
DTSRun /S "192.168.2.1" /U "sa" /P "changeme" /N "Delete AppErrors"
C.
Then I follow the instructions here to find the code:
https://learn.microsoft.com/en-us/previous-versions/sql/sql-server-2008-r2/cc645945(v=sql.105)
which amounted to:
In Object Explorer, expand the Management folder.
Expand the Legacy subfolder.
Expand the Data Transformation Services subfolder to show packages.
D.
I right click on it and choose Open. I get this error:
I should not have to install anything because the person who put this on the machine must have been able to edit it. (this person is completely unavailable so I can't ask him). The reason I need access to it is that we are upgrading the machine.

First time coding and confused - Echo

Apologies for incredible ignorance. First time ever looking at or trying coding in any form and all naturally a bit confusing and overwhelming.
Trying to keep it super basic I'm attempting to build something basic for Amazon Echo by working through this article - https://developer.amazon.com/blogs/post/Tx3DVGG0K0TPUGQ/updated-alexa-skills-kit-fact-template-step-by-step-guide-to-build-a-fact-skill
Have got to Step 2.3
Once you have the source downloaded [done], node installed and npm updated, you are ready to install the ASK-SDK. Install this in the same directory as your src/index.js file for your skill. Change the directory to the src directory of your skill, and then in the command line, type: npm install --save alexa-sdk
I've moved the SDK into the same folder as the source - in downloads folder. Am confused on changing the directory to the same as my skill. As far as I know there is no skill yet so not sure where to move it to.
When type in npm install --save alexa-sdk
returns
npm WARN enoent ENOENT: no such file or directory, open '/Users/OwenLee/package.json'
npm WARN OwenLee No description
npm WARN OwenLee No repository field.
npm WARN OwenLee No README data
npm WARN OwenLee No license field.
working on a mac so don't really know how/where to access this, but assuming this is where i need to move the files to?
Very sorry for baby-basic knowledge. Just trying to at least get a foot in the door as know need to learn this stuff but everything i read seems to assume i already have a working knowledge of coding : S
any help would be awesome - inc. any advice on steps after that you can probably see i'll trip up on
thanks!!
oven121
So as far as the directory /Users/OwenLee/ this would be your home folder on a Mac. The Root / of your HDD can be reached through Finder by clicking on Macintosh HD (or whatever you named your main hard drive) in the side bar. If you open up a new Terminal window it will be the directory that the terminal starts in. You should be able to fix your problem by taking the file packages.json, which should be wherever you downloaded the SDK to, and placing it in your home folder, then re-running the command.
Now don't let me change your mind if you're truly committed, but if you have absolutely no experience with programming I would recommend starting with something a bit simpler than Java or Javascript. Object oriented languages can be both very convoluted and difficult to get the hang of for beginners (I personally have been writing native languages like C for years and am just now starting to understand how Java works.).
If it is an option I recommend starting with a language that your Mac has built in support for. Perhaps start with Bash scripting or Apple Script making basic scripts to do things you find tedious to do manually in a terminal, or get to know the basics of processor-native languages like C & C++ by making some basic programmes to display text when it is run, or to ask the user to type something, and say back what they typed. Finally since you are on a Mac you can get Xcode for free in the app store, it will configure itself and you could play around with it to learn how macOS handles windows, perhaps start by making a basic programme window with a few buttons that do different things when clicked.
If you have any interest in my suggestions you can find some info about bash scripting here: https://linuxconfig.org/bash-scripting-tutorial the tutorial says it assumes the reader has no previous knowledge of Bash, and most commands should work fine in the version of Bash built into your Mac's Terminal app.
If you take more interest in C++ this is the site that I used to learn to write it, and learn how native languages work: http://www.cplusplus.com/doc/tutorial/
Finally here is a basic C++ programme called "Hello World", it is somewhat of an initiation rite of C/C++ students to write this programme and learn how each part of it works:
//HelloWorld.cpp the double slash tells the compiler and user that everything after it on this line is a comment, not code//
#include <iostream> //The octothorp '#' lets the compiler know it needs to use the library named inside the pointed brackets '</>' when it builds the programme. 'iostream' stands for In-Out Stream, and handles basic text, and basic processor commands//
using namespace std; //This line tells the compiler that any line that says to show text or ask the user to type something should use regular text and not a special format//
int main() //'int' stands for integer, any time you make a variable that contains only an integer you should put this in front of it's name, and 'main' is the name of the integer. The empty parentheses tells the compiler that this is a function, rather than a number//
{ //The open curly bracket '{' tells the compiler where the function starts
cout<<"Hello World"; //'cout' stands for 'character out' and is for showing basic text in the terminal window. The double pointy 'out' brackets '<<' tells the compiler that the text should be sent out of the programme rather than loaded into a variable, the text inside the quotes is what will be shown on the screen, and the semi colon tells the compiler where the command ends, it has to be put at the end of any command that is inside of a function//
return 0 //The command 'return' is for telling the compiler whether or not an error has occurred, 0 means the programme ran fine, 1 means something went wrong, either way the programme closes when it runs the command 'return'//
} //the closed curly bracket tells the compiler where the function ends//
Good luck with your programming, and if you have any questions unrelated to this thread please feel free to private message me, or create a new question and tag me in it so that I get notified.

Shorcut for `Run Line(s)` in Octave / Matlab

In RStudio it is Ctrl+Enter, while in PyCharm it is Ctrl+backslash, but I can't find a similar shortcut for Octave (not so interested in Matlab). There has to be a way to run a single line of code on the editor without running the entire document. I know there is a method to run chunks of code, but this doesn't seem practical, either.
You need to select the code that you want to run first. The actual shortcut to then execute the selection is configurable (Edit > Preferences...) but defaults to F9.
Or you can right click on the editor which shows you the options and shortcut:

BiarEnginer.jar/Command Line Import Documentation/Usage

Anyone know where the documentation is for the properites file?
I am trying the following exportQuery:
select * form ci_infoobjects where si_kind like 'FavoritesFolder' and si_name like 't%'
It is correctly grabbing the users but, is not biaring any of the folders/reports that said user has.
Suggestions?
Ok here is what I have found out.
documentation: on the command line importe is in the bi_vip pdf provided by SAP (which I will provide a link to later).
usage: My query isn't exactly correct but, removing the si_name portion should get you th right result.
issues: It seems that the command line importer does not gracefully handler export errors. Any export error it receives the command line will kill itself.
work around: I am pretty much duplicating the ImportWizard in java at this using API BIAROutput and IException.
I will hopefully post back my source code for the command line import tool in java.