How to add a project-test.jar to a package? - sbt

For our test servers, we want to package our tests in a debian. In sbt, I can generate the test-jar using:
publishArtifact in Test := true
I've looked into using member in Universal and addArtifact() but I am having trouble finding a solution.
How do I add the test-jar into the package?

There are two options.
Add to mappings
This is very simply done with this small snippet you can add to your build.sbt
mappings in Universal += {
// generates the test package
val testjar = (packageBin in Test).value
// maps this file to your lib folder in your output package
testjar -> s"lib/${testjar.getName}"
}
Add it to publishTask
This will generate the test package and publishes it, too. But it won't be added to the debian package.
import com.typesafe.sbt.packager.SettingsHelper
SettingsHelper.addPackage(Debian, packageBin in Test, "jar")

Related

How to load a git branch from another R package

In R, how I load one package's git branch from another package?
There are two packages, call them producer and consumer1. I am refactoring my code by moving a bunch of function definitions and tests from producer to consumer1.
I'm creating git branches, rfctrProd and rfctrCons1 for producer and consumer1. In rfctrCons1, I need a statement doing something like
#` #import producer, gitBranch = rfctrProd
Also, I'll to do similarly with other packages which import producer, to make sure I haven't broken them either. (I think the functions I'm refactoring are only used by consumer1, but I want to be sure before I merge my changes.)
You don't use roxygen comments to specify the import branch, just the functions themselves. You can specify the branch in the DESCRIPTION file, under Remotes:. Assuming it's Github (the default), you can do:
Remotes:
username/producer/rfctrProd
If it's not Github, have a look here for the other syntax.

Extend map from other packages at compile time

I'm trying to extend a map across packages at 'compile time'. Is this possible?
I have package A with a predefined map:
package A
var MyMap = map[string]string{"key1": "value", "key2": "value"}
And I would like to extend the map during 'compile time'. This shall be done in another package. E.g. like so (not working code ofc.):
package B
import "A"
A.MyMap.Slice1["key3"] = "value" // extend the map during compile time
Is this somehow possible?
You can't do this "at compile" time. In fact, the composite literal that package A uses, that also will be constructed and used at runtime. There are no composite literal constants.
Going further, whatever code you write in package B, if it imports package A, code of package B will only run after package A has been initialized, including the map you posted.
If you want A.MyMap to have a different value before it can be seen by any other package, you should modify the source of package A. This could be a generated additional file, which could use a package init() function, assigning a new value to MyMap, or adding new values to it.
If you can, you could also modify package A so that the initialization of MyMap is moved to a different source file, one that can be generated.
It is actually extension at runtime but it should fit your example.
Use init function.
package B
import "A"
func init() {
A.MyMap["key3"] = "value"
}
You pass a string at linking time with command
go build -ldflags '-X somemap={"k":"v"}'
and then parse it to map at run time. You can easily use JSON format.
See more on GcToolchainTricks.

Created R Package, Unable to Display Photo

Update
Issue resolved
Update, still not working
Tried the following in R file
(1) deleted both library(...) packages
(2) Added #import jpeg before ShowPalettePhoto() and #import tidyverse before RanglaPunjab() so roxygen automatically adds to NAMESPACE.
After running devtools::document(), ran devtools::use_package("jpeg") and devtools::use_package("tidyverse") to automatically add to DESCRIPTION.
Unfortunately, even in testing, I cannot get JPEG photo.
Here is GitHub repository, https://github.com/ArtieLadie/RanglaPunjab
I created R package according to this tutorial
It worked and I was able to execute all commands, including a function to display photo in another directory.
I uploaded to my GitHub account. Anyone can install package in R environment with install_github("ArtieLadie/RanglaPunjab")
I am able to run functions by adding RanglaPunjab:: in front of it, i.e.
RanglaPunjab::PaintPalette("Jutti")
?RanglaPunjab::MergePalette
However, when I try to run ?RanglaPunjab::ShowPalettePhoto("Teej") I get
Error in readJPEG(x, native = TRUE) : could not find function "readJPEG"
Before creating the package I added function to set working directory to file location, but it was creating errors when I ran install("RanglaPunjab"), i.e. "Cannot execute"
Here are the exact commands I had, which I had to delete from code
library(rstudioapi)
current_path <- getActiveDocumentContext()$path
setwd(dirname(current_path ))
Please help
Your dependencies are not handled correctly. Here you explicitly load packages with library(...). That is not how one does that in an R package. You should add your dependencies to the Imports: section of the DESCRIPTION file and use the package::function() syntax when calling the function. c.f. http://r-pkgs.had.co.nz/description.html#dependencies.
In addition, if you want the images to be installed with your package, you should place them for example in inst/pics. You can then get the path to these files with
system.file("pics", <file-name>, package = "RanglaPunjab")

sbt 1.1.1 ignores dependencies with classifiers for transitive dependencies

I built a library against multiple versions of another dependencies, using classifiers to separate them.
Now I want to reference this:
libraryDependencies += "com.mycompany" %% "mylib" % "x.y.z" classifier "otherlib-foo"
When I run sbt compile the classifier is partly ignored. The mylib is correctly loaded but it depends on another library with the classifier, and it only resolves its dependency without it.
What am I missing?
Followup 1
I added:
transitiveClassifiers in Global := Seq(Artifact.SourceClassifier, "otherlib-foo")
but it didn't change anything
Followup 2
When I change the classifier by changing my Git branch (There need to be some source adjustments for the dependent library) and republish it, Spark overwrites the pom.
Currently I stuck to putting the "classifier" into the version string (i.e. "x.y.z-otherlib-foo" as a workaround and using this one, but this can't be the way...

Is there any existing syntax checker for GNU R

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:

Resources