It turns out that this is possible with the largely undocumented namespace
package:
library(namespace)
ns <- makeNamespace("myNamespace")
assign("test", 7, env=ns)
setNamespaceInfo(ns, "exports", as.environment(list(test="test")))
print(myNamespace::test)
Not sure how safe this is though. For example sessionInfo
doesn't work anymore:
> sessionInfo()
Error in if (pkgpath == "") { : argument is of length zero