Is there any existing tool to perform the same function as 'jslint' or 'php -l'?
For a large scale project, how can we ensure source code without any typo error before any unit test.
There is the codetools package (especially the checkUsage function) and the lint function in the svTools package.
Yes I got the lintr checker from here to work:
https://www.r-project.org/nosvn/pandoc/lintr.html
https://github.com/jimhester/lintr
Installation for Vim:
Put the file syntastic/lintr.vim under the syntastic/syntax_checkers/r directory. If you are using pathogen this directory is ~/.vim/bundles/syntastic/syntax_checkers/r.
Then add the following lines to your .vimrc.
let g:syntastic_enable_r_lintr_checker = 1
let g:syntastic_r_checkers = ['lintr']
Start vim and it should work, here is mine:
Related
I am running R script in the php code in apache webserver, in my script I am giving code for loading (kohonen library). whole R-script will be running through php coding as exec("Rscript script.R");
R code:
library("kohonen")
load(file = "som.rda")
tr<-read.csv("trainnew1.csv")
compile11<-tr
write.table(compile11, file = "kohonen1.txt")
and etc..........
in terminal this code is running, but while giving in php it is not executing and loading the library
for checking the library loading, i wrote simple code for addition by loading library in first line
example
library("kohonen")
a<-3
b<-5
c<-a+b
print(c)
it is not printing c in output file, because of kohonen library
same addition i tried with loading nnet library
example
library("nnet")
a<-3
b<-5
c<-a+b
print(c)
It is printing c in the output file. problem is with loading kohonen library
please suggest me, how to load kohonen libary and then how to fix this problem
I am sorry, I might not have the answer you need. I just want to emphasize another thing. Please never naming a variable with c. It is an R reserved word. You can change to cc or something else. Perhaps this is also the cause of your R session not working.
How to avoid the following NOTE that is appearing in R CMD check with the new R development version ( R Under development (unstable) (2017-02-15 r72179))?
• checking for unstated dependencies in examples ... OK
• checking line endings in C/C++/Fortran sources/headers ... OK
• checking compiled code ... NOTE
File ‘pkgname/libs/pkgname.so’:
Found no calls to: ‘R_registerRoutines’, ‘R_useDynamicSymbols’
It is good practice to register native routines and to disable symbol
search.
For example in Hmisc
The message is somewhat arcane. I looked around also in other packages and I found that the useDynLib(packagename) in the NAMESPACE file was replaced by useDynLib(packagename, .registration = TRUE).
In addition, I added a .c file, named registerDynamicSymbol in the src/ directory with the following code:
// RegisteringDynamic Symbols
#include <R.h>
#include <Rinternals.h>
#include <R_ext/Rdynload.h>
void R_init_markovchain(DllInfo* info) {
R_registerRoutines(info, NULL, NULL, NULL, NULL);
R_useDynamicSymbols(info, TRUE);
}
I took this suggestion from GitHub Rcpp. The canonical reference is in Writing R Extensions
Also R Devel Mailinglist provided supplementary infos.
UPDATE
The most direct straightforward approach is:
use the current R Development Version (that will eventually become 3.4)
Run the tools::package_native_routine_registration_skeleton(".") and copy and paste the full output in a packagename_init.c file to be put in src/
update NAMESPACE, verifying that useDynLib(packagename, .registration = TRUE)
If necessary, replace the exportPattern with export( list of object to be exported )
UPDATE 18th July
As noted by #Symbolix using the most recent version of R and RStudio's devtools the point 2. (init.c files) appears handled by either devtools (using RStudio check digit) or tools packages.
I ran into a persistent issue with a Windows build package. (.dll instead of .so)
The accepted answer above should also resolve this issue for Windows, but if it does not resolve it. Make sure that objdump.exe is pointing the appropriate arch. i.e. .../Mingw_64/bin/objdump.exe. This can be checked from a command prompt with which objdump.exe. Somehow a 32-bit objdump.exe found its way into a higher priority position in my path. This arch mismatch will produce a File format not recognized error.
First I did exactly what Giorgio Spedicato says. But still got NOTE warnings. Finally I got problem solved by doing this:
Sys.setenv(PATH = paste(Sys.getenv("PATH"),
"C:\RTools40",
"C:\RTools40\mingw64\bin",
sep = ";"))
Have to add mingw64\bin to PATH because that's where objdump.exe is located
When trying to use the sample code for SubgraphMining (the example is on 35th page), I get an error:
"Error in setwd(paste(Sys.getenv("R_HOME"), "library", "subgraphMining", :
cannot change working directory"
I'm using RStudio 0.97.551, 32-bit R (2.15.3 - this version of R was recommended to use with subgraphMining), igraph0 (was recommeded too, instead of igraph library), Java installed. Operation system is Windows 8.
Can anyone help me with the issue?
The error message is coming from the gspan function of subgraphMining, from here:
setwd(paste(Sys.getenv("R_HOME"), "library", "subgraphMining",
"parsemis", sep = "\\"))
The reason for it is that R uses / as path separator, and not \\, which only works on windows. A workaround is not modify the function and use / instead of \\.
Btw. this has nothing to do with the igraph package, so I'll remove that tag.
In my case, it displayed the error because I expected it to create a new folder which I mentioned in the path in setwd. Unfortunately, R does not have this functionality and the matter was resolved when I created the folder and then used setwd command.
I know it's almost 1 year since this question was posted. I encountered the same problem with subgraphMining package. A quick hack is: You can write "gspan" on RStudio's command line and it will show the function, copy that function and create your own function in your own script (of course with new name, let's say gspanNew) and fix it by replacing "\\" with "/", as Gabor Csardi pointed out.
Cheers! :)
You can always use file.path("path","with","code") instead of simple paste in order for your code to be OS independent.
This is more of an annoyance than it is a problem, but is there any way to prevent the line "overflow" that occurs when documentation in R is compiled and a line is too long?
A snippet of some documentation created with R CMD Rd2pdf [options] files:
I can't find mention of this anywhere, and the only options for Rd2pdf are:
Options:
-h, --help print short help message and exit
-v, --version print version info and exit
--batch no interaction
--no-clean do not remove created temporary files
--no-preview do not preview generated PDF file
--encoding=enc use 'enc' as the default input encoding
--outputEncoding=outenc
use 'outenc' as the default output encoding
--os=NAME use OS subdir 'NAME' (unix or windows)
--OS=NAME the same as '--os'
-o, --output=FILE write output to FILE
--force overwrite output file if it exists
--title=NAME use NAME as the title of the document
--no-index don't index output
--no-description don't typeset the description of a package
--internals typeset 'internal' documentation (usually skipped)
Sorry for the spoiler: One solution is not using roxygen2 in extremis for package maintenance. Why not maintain your DESCRIPTION manually? You don't need many changes and it looks so much better...
The 'Collate' is really not needed for the vast majority of packages.
Why not follow the tradition of many bioconductor packages, 'Matrix' etc, of
putting S4 class definitions (including reference classes) in a file 'AllClasses.R' and maybe use 'AllGenerics.R' as well, and for the rest, collation order should not matter.
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.