I am trying to execute a windows only executable called (groundfilter.exe from FUSION) within Rstudio on Ubuntu.
I am able to run groundfilter.exe from a terminal using wine as follows:
wine C:/FUSION/groundfilter.exe /gparam:0 /wparam:1 /tolerance:1 /iterations:10 test_Grnd.las 1 test.las
The executes fine and produces file test_Grnd.las OK.
But when i try to do this from within Rstudio using system() it doesn't quite work, and no output file is produced (unlike from terminal). I do this:
command<-paste("wine C:/FUSION/groundfilter.exe",
"/gparam:0 /wparam:1 /tolerance:1 /iterations:10",
"/home/martin/Documents/AUAV_Projects/test_FUSION/test_FUSION/test_GroundPts.las",
"1",
"/home/martin/Documents/AUAV_Projects/test_FUSION/test_FUSION/test.las",sep=" ")
system(command)
The executable appears to be called OK in Rstudio console, but run as if no file names were supplied. The output( truncated ) is:
system(command)
GroundFilter v1.75 (FUSION v3.60) (Built on Oct 6 2016 08:45:14) DEBUG
--Robert J. McGaughey--USDA Forest Service--Pacific Northwest Research Station
Filters a point cloud to identify bare-earth points
Syntax: GroundFilter [switches] outputfile cellsize datafile1 datafile2 ...
outputfile Name for the output point data file (stored in LDA format)
This is the same output from the terminal if the file names are left off, so somehow my system call in R is not correct?
I think wine will not find paths like /home/martin/....
One possibility would be to put groundfilter.exe (and possibly dlls it needs) into the directory you want to work with, and set the R working directory to that directory using setwd().
The other possibility I see would be to give a path that wine understands, like Z:/home/martin/....
This is not an authoritative answer, just my thoughts, so please refer to the documentation for the real story.
Related
Suppose that I have a R script called test.R, stored at C:\, with the following content:
x <- "Hello Stackoverflowers"
print(x)
To run it via terminal one could simply call:
Rscript C:\test.R
And as expected, the result will be:
However, what I wonder is whether there is a way to run test.R via Windows console but after that staying within the executed R session instead of closing and going back to the console cursor? That is, staying inside the R session instead of going back, in the image above, to C:\R\R-3.4.1\bin>.
For instance, when compiling Python code with python.exe I can easily accomplish a similar thing by passing the -i parameter to the python.execall.
How could I do that with R?
Add this to your .Rprofile:
STARTUP_FILE <- Sys.getenv("STARTUP_FILE")
if (file.exsts(STARTUP_FILE)) source(STARTUP_FILE)
and then set the indicated environment variable outside of R and then run R. e.g. from the Windows cmd line:
set STARTUP_FILE=C:\test.R
R
... R session ...
q()
Variations
There are many variations of this. For example, we could make a copy of the .Rprofile file in a specific directory such as ~/test, say, and add this code to that copy
source("~/test/test.R")
in which case R would only run test.R if R were started in that directory.
I have a command that works when typed into the Terminal on a Mac (OSX El Cap), but the same command fails when called from R using system().
I am trying to batch-process MODIS satellite files using the MODIS Reprojection Tool. My software is all up to date.
This is a simple example in which I mosaic two files. The names of the two files are in a text input file called input.list. The command just tells the mrtmosaic routine where to find the input list and where to put the output.
This command works correctly in the Terminal:
/Applications/Modis_Reprojection_Tool/bin/mrtmosaic -i ~/temp/input.list -o ~/temp/output.hdf
However, if I put exactly the same string into a variable and run it from R (using RStudio), it fails:
comstring<-"/Applications/Modis_Reprojection_Tool/bin/mrtmosaic -i ~/temp/input.list -o ~/temp/output.hdf"
system(comstring)
Warning: gctp_call : Environmental Variable Not Found:
MRT_DATA_DIR nor MRTDATADIR not defined
Error: GetInputGeoCornerMosaic : General Processing Error converting lat/long coordinates to input projection coordinates.
Fatal Error, Terminating...
The strange thing is that the system knows what the environment variables are. In the terminal, the command
echo $MRT_DATA_DIR
shows the correct directory: /Applications/Modis_Reprojection_Tool/data
I don't see why it would have trouble finding the variables from an R system() call when it has no trouble in the Terminal. I'm very stumped!
I posted this question to the R help list, and two people there helped me solve the problem. They suggested (if I understood right) that the problem was that OSX El Capitan was not successfully passing environment variables to R. In any case:
These do not work:
Setting the environment variable in my .bash_profile (for example by adding and exporting MTR_DATA_DIR="/Applications/MRT/data"); or
Setting the environment variable by adding the same line to the .Rprofile file in my home directory.
These do work:
Setting the environment variable at the R command line by typing Sys.setenv(MRT_DATA_DIR="/Applications/MRT/data"); or
Setting the environment variable in the .Renviron file (which is in my home directory) by adding MRT_DATA_DIR="/Applications/MRT/data" to it; or
Typing MRT_DATA_DIR="/Applications/MRT/data" open -a Rstudio in the Terminal. This last method is an effective workaround and a useful tool in a bag of tricks, but is slightly clumsier since one has to remember to open RStudio this way each time.
I have written an R package in which the names of the functions are in Turkish.
I wanna take that package to CRAN with internalization. I changed all of the Turkish names (of functions, of data sets) to English so that everybody can easily use the package. After that, I followed regular "library(roxygen2); library(devtools); library(digest); roxygenize("causfinder"); build("causfinder"); install("causfinder"); library(causfinder)" way in process.
At the end, all of the functions appear with their English names this time in the Object Browser of Revolution R (version 7.1.0 Academic License). So, for the conversion of the names of the functions, all are OK.
Problem:
But, interestingly, not all of the names of data files in the package are not converted to English.
What I did to solve the problem till now:
I tried every sort of trick I know:
1. I deleted package from library location (I have only 1 such location: "C:\Revolution\R-Enterprise-7.1\R-3.0.2\library") completely and rebuild package and install again.
2. I deleted package from working directory "C:\Users\erdogan\Documents\Revolution", and triggered "library(roxygen2); library(devtools); library(digest); roxygenize("causfinder"); build("causfinder"); install("causfinder"); library(causfinder)" process
3. By giving possibility to Buffer effects, I deleted "C:\Users\erdogan\Documents\Revolution\32_7.1" so that "PackageXMLs\causfinder.xml" in that folder does not meddle in improperly. I had R created "32_7.1" folder by restarting Revo R.
4. I applied tricks suggested by "Dirk Eddelbuettel" here:
Update the dataset in an installed package
"updating the source and re-installing with a new distinctive version number": Not worked.
"by forcefully overwriting it, possibly. Not the proper way to do it.": How to apply that force?
My findings that may perhaps give an idea to professionals to solve the problem:
Only one of the data files correctly got renamed, and at the end of that data file in object browser "[Package causfinder version 1.0 Index]" appears. The names of all the other data files are still in Turkish and at the end of those data files, the phrase "[Package causfinder version 1.0 Index]" does not appear! I did not do anything peculiar to that data file whose internalization was done correctly.
Any help will be greatly appreciated.
Step by Step Solution: (Notebook with 32-bit Windows; GUI: Revolution R Enterprise (32-bit))
1. Prepare the environment by cleaning related folders:
1a. Delete the package folder in R's library location via Windows Explorer:
(I have only 1 such location: I deleted "C:\Revolution\R-Enterprise-7.1\R-3.0.2\library\causfinder" folder)
(Run ".libPaths()" to see R's library locations and delete the package's folder from all R's library locations)
1b. Delete the package folder in R's working directory via Windows Explorer:
(I have only 1 such location: I deleted "C:\Users\erdogan\Documents\Revolution\causfinder" folder)
(Run "getwd()" to see R's working directory and delete the package's folder from all R's working directories)
1c. Delete the "32_7.1" or "64_7.1" folder (32bit, 64 bit R, whichever you use) from R's working directory via Windows Explorer:
The .xml file of the package in discussion in this folder may sometimes meddle in and affect the results of R commands, and gives unexpected results.
Delete "C:\Users\erdogan\Documents\Revolution\32_7.1" folder where "PackageXMLs\causfinder.xml" is located.
(When Revolution R restarted, 32_7.1 (or 64_7.1) folder is created automatically if it doesn't exist)
Restart Revolution R now.
2. Create .rda and .Rd files via R and put them in relevant location.
((For English ones, I created .rda and .Rd files like this:
V6Stationary43Obs.df <-
read.csv("C:/Users/erdogan/Documents/Revolution/V6Stationary43ObsWithoutX.csv", header = TRUE, stringsAsFactors = FALSE)
# create V6Stationary43Obs.df.rda dataset file; df to denote data frame
save(V6Stationary43Obs.df, file="V6Stationary43Obs.df.rda")
prompt(V6Stationary43Obs.df) # creates V6Stationary43Obs.df.Rd help file))
((For Turkish ones, I performed the followings once upon a time
D6Duragan43Gozlem.dvc<- read.csv("C:/Users/erdogan/Documents/Revolution/D6Duragan43GozlemXsiz.csv", header = TRUE, stringsAsFactors = FALSE)
# create D6Duragan43Gozlem.vc.rda dataset file; df to denote data frame
save(D6Duragan43Gozlem.vc, file="D6Duragan43Gozlem.vc.rda")
prompt(D6Duragan43Gozlem.vc) # create D6Duragan43Gozlem.vc.Rd help file))
3. Take the .rda and .Rd files (created in Step2) to the "data" and "man" folder in R's working directory via Windows Explorer:
V6Stationary43Obs.df.rda dataset file --> C:\Users\erdogan\Documents\Revolution\causfinder\data
V6Stationary43Obs.df.Rd help file --> C:\Users\erdogan\Documents\Revolution\causfinder\man
4. Fill at least the "Title" and "Description" tags of .Rd files (created in Step3) via R:
"File - Open - File... - V6Stationary43Obs.df.Rd"
\title{
V6Stationary43Obs is..... .
}
\description{
V6Stationary43Obs does..... .
}
5. Apply roxygenization:
library(roxygen2)
library(devtools)
library(digest)
roxygenize("causfinder")
build("causfinder")
install("causfinder")
library(causfinder)
Solution: (Notebook with 64-bit Windows; GUI: Revolution R Enterprise (32-bit))
The above process is performed with the following additional actions:
1. The datasets are created as usual (for example; ".df" to denote data frame):
X.df <- read.csv("C:/Users/erdogan/Documents/Revolution/X.csv", header = TRUE, stringsAsFactors = FALSE)
save(X.df, file="X.df.rda") # X.df.rda dataset is created
prompt(X.df) #X.df.Rd help file is created.
2. Revolution R is closed, and in the working directory, the folder "32_7.3" is deleted. We delete this folder because: The information (functions, data sets, etc.) of our package (here: causfinder) are stored as .xml file in 32_7.3. However, this .xml file cannot update itself once we add our data sets one by one.
3. Revolution R is opened (the folder "32_7.3" is re-created). At this point, Step 5 above (Applying roxygenization) is performed. Once we do this, the datasets are visible in Revolution R's Object Browser.
4. The control of everything realized seamlessly: Go to the "data" folder of package's library location. Here, you must see only ".rdb, .rds, .rdx" files.
Solution: (Notebook with 64-bit Windows; GUI: Revolution R Enterprise (64-bit))
Apply the steps for 32-bits. If everything is OK, then fine: you are done. If not OK (i.e. datasets are not visible in Object Browser of Revo R and data folder of the package in the library location does not include only the .rdb, .rds, .rdx files), then do not panic:
You can still work with the datasets you created that are seen as .rda files in the package's library location: Use "data" command:
data(YourDatasetName, package = causfinder, lib.loc = YourLibraryLocation)
Learn about data command more. Upon using this command, you get the dataset in the Object Browser as an object of Global Environment.
I'm a social scientist having a hard time struggling through the technical instructions for integrating the graphing program dotdocumented here with the sem package documented here.
I have successfully run the command pathDiagram in the sem package, which outputs code that is presumably supposed to be read into dot. The documentation for the sem package says
"To obtain graphics output directly, the dot program must be on the system search path."
I'm sure that this is a totally mundane question, but I'd really appreciate help. I'm lost.
In R execute this command:
Sys.which("dot")
This will tell you whether a system call will be able to find your 'dot' installation. You did install 'dot', right?
The Graphviz pkg file for MacOS greater than or equal to 10.6 (and your ML is 10.8) can be obtained from AT&T labs: http://www.graphviz.org/Download.php
After installing from its .pkg file (with the same Graphviz version 2.30.1 on OSX 10.6.8) I get:
> Sys.which(c("dot"))
dot
"/usr/local/bin/dot"
This does NOT open up dot. It merely confirms that the dot program can be found on by R. Running the first example on hte ?pathDiagram page only outputs a source file to the console which could be used for dot to the console, because no file argument is given, but if you add a file argument it creates a pdf file using dot with a message to the console screen:
pathDiagram(sem.dhp, min.rank='RIQ, RSES, RParAsp, FParAsp, FSES, FIQ', file="test",
max.rank='ROccAsp, REdAsp, FEdAsp, FOccAsp', output.type="graphics", graphics.fmt="pdf")
#Running dot -Tpdf -o test.pdf test.dot
This produced a file in my working directory that could be viewed with Preview.app. If you want to use dot on its own, you will need to read its manual and follow the instructions for using it in a standalone manner.
Update as per comments:
If when you type which dot in terminal, you get a response with a path, then it is safe to say that graphviz is installed.
As per pathDiagram's manual (ie, ?pathDiagram), it is not intended to return a value.
Instead, use the file argument to specify where to save the output to.
pathDiagram(model=SomeModelInR, file="path/to/file", ...)
This seems to be more of a general mac os x question, but anyway, here we go:
In your applications > utilities folder, open up terminal.
(i'm assuming dot is called dot if not please modify accordingly)
Type which dot
- this will show you the path to dot, perhaps something like /usr/bin/dot
- in this case, the path you are looking for in the next part is /usr/bin
Type echo $PATH
- this will show you several paths separated by :
- If the path you got with which dot is listed as one of those paths, then you are all set.
- If not, please see the link below on how to modify
Also see:
How To Edit Your PATH Environment Variables On Mac
I want to find the location of the script .R files which are used for computation in R.
I know that by typing the object function, I will get the code which is running and then I can copy and edit and save it as a new script file and use that.
The reason for asking to find the foo.R file is
Curiosity
Know what is the algorithm used in the numerical computations
More immedietly, the function from stats package I am using, is running results for two of the arguments and not the others and have to figure out how to make it work.
Error shown by R implies that there might be some modification required in the script file.
I am looking for a more general answer, if its possible.
Edit: As per the comments so far, here is the code to compute spectrum of a time series using autoregressive methods. The data input is a univariate series.
x = ts(data)
spec.ar(x, method = "yule-walker") 1
spec.ar(x, method = "burg") 2
command 1 is running ok.
command 2 gives the following error.
Error in ar.burg.default(x, aic = aic, order.max = order.max, na.action = na.action, :
Burg's algorithm only implemented for univariate series
I did try specify all the arguments correctly like na.action=na.fail, order.max = NULL etc but the message is the same.
Kindly suggest possible solutions.
P.S. (This question is posted after searching the library folder where R is installed and zip files which come with packages, manuals, and opening .rdb, .rdx files)
See FAQ 7.40 How do I access the source code for a function?
In most cases, typing the name of the function will print its source
code. However, code is sometimes hidden in a namespace, or compiled.
For a complete overview on how to access source code, see Uwe Ligges
(2006), “Help Desk: Accessing the sources”, R News, 6/4, 43–45
(http://cran.r-project.org/doc/Rnews/Rnews_2006-4.pdf).
When R installs a package, it evaluates all the ".R" source files and re-saves them into a binary format for faster loading. Therefore you typically cannot easily find the source file.
As has been suggested elsewhere, you can simply type the function name and see the source code, or download the source package and find the source there.
library(plyr)
ddply # prints the source for ddply
# See the content of the R directory for plyr,
# but it's only binary files:
dir(file.path(find.package("plyr"), "R"))
# [1] "plyr" "plyr.rdb" "plyr.rdx"
# Get the source for the package:
download.packages("plyr", "~", type="source")
# ...then unpack and inspect the R directory...
.libPaths() should tell you all of your current library locations. It's possible to have more than one installation of a package if there are two libraries but only the one that is in the first library will be used. Unless you offer the code and the exact error message, it's not likely that anyone will be able to offer better advice.
I think you are asking to see what I call the source code for a function in a package. If so, the way I do it is as follows, which has worked successfully for me on the three times I have tried. I keep these instructions handy in a few places and just copied and pasted them here:
To see the source code for a function in Program R download the package containing the function. Specifically, download the file that ends in "tar.gz". This is a compressed file. Expand the compressed file using, for example, "WinZip". Now you need to open the uncompressed file that ends in ".tar". Download the free software "7-Zip". Click on the file "7zFM.exe" and navigate to the directory containing the ".tar" file. You can extract the contents of that ".tar" file into a new folder. The contents consist of R files showing the source code for the functions in the R package.
EDIT:
Today (July 8, 2012) I was able to open the 'tar.gz' file using the latest version of 'WinZIP' and could copy the contents (the source code) from there without having to use '7-Zip'.
EDIT:
Today (January 19, 2013) I viewed the source code for functions in base R by downloading the file
'R-2.15.2.tar.gz'
To download that file go to the http://cran.at.r-project.org/ webpage and click on that file in this line:
"The latest release (2012-10-26, Trick or Treat): R-2.15.2.tar.gz, read what's new in the latest version."
Unzip the file. WinZip will work, or it did for me. Then search your computer for readtable.r or another base R function.
agstudy noted here https://stackoverflow.com/questions/14417214/source-file-for-r-function that source code for read.csv is located in the file readtable.r, so do not expect every base R function to have its own file.